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    /// Create an unqualified column reference (e.g. `name`).
1233    pub fn column(name: impl Into<String>) -> Self {
1234        Expression::Column(Column {
1235            name: Identifier::new(name),
1236            table: None,
1237            join_mark: false,
1238            trailing_comments: Vec::new(),
1239            span: None,
1240        })
1241    }
1242
1243    /// Create a qualified column reference (`table.column`).
1244    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1245        Expression::Column(Column {
1246            name: Identifier::new(column),
1247            table: Some(Identifier::new(table)),
1248            join_mark: false,
1249            trailing_comments: Vec::new(),
1250            span: None,
1251        })
1252    }
1253
1254    /// Create a bare identifier expression (not a column reference).
1255    pub fn identifier(name: impl Into<String>) -> Self {
1256        Expression::Identifier(Identifier::new(name))
1257    }
1258
1259    /// Create a NULL expression
1260    pub fn null() -> Self {
1261        Expression::Null(Null)
1262    }
1263
1264    /// Create a TRUE expression
1265    pub fn true_() -> Self {
1266        Expression::Boolean(BooleanLiteral { value: true })
1267    }
1268
1269    /// Create a FALSE expression
1270    pub fn false_() -> Self {
1271        Expression::Boolean(BooleanLiteral { value: false })
1272    }
1273
1274    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1275    pub fn star() -> Self {
1276        Expression::Star(Star {
1277            table: None,
1278            except: None,
1279            replace: None,
1280            rename: None,
1281            trailing_comments: Vec::new(),
1282            span: None,
1283        })
1284    }
1285
1286    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1287    pub fn alias(self, name: impl Into<String>) -> Self {
1288        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1289    }
1290
1291    /// Check if this is a SELECT expression
1292    pub fn is_select(&self) -> bool {
1293        matches!(self, Expression::Select(_))
1294    }
1295
1296    /// Try to get as a Select
1297    pub fn as_select(&self) -> Option<&Select> {
1298        match self {
1299            Expression::Select(s) => Some(s),
1300            _ => None,
1301        }
1302    }
1303
1304    /// Try to get as a mutable Select
1305    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1306        match self {
1307            Expression::Select(s) => Some(s),
1308            _ => None,
1309        }
1310    }
1311
1312    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1313    ///
1314    /// Returns an empty string if generation fails. For dialect-specific output,
1315    /// use [`sql_for()`](Self::sql_for) instead.
1316    pub fn sql(&self) -> String {
1317        crate::generator::Generator::sql(self).unwrap_or_default()
1318    }
1319
1320    /// Generate a SQL string for this expression targeting a specific dialect.
1321    ///
1322    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1323    /// syntax variations) are applied automatically.  Returns an empty string if
1324    /// generation fails.
1325    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1326        crate::generate(self, dialect).unwrap_or_default()
1327    }
1328}
1329
1330impl fmt::Display for Expression {
1331    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1332        // Basic display - full SQL generation is in generator module
1333        match self {
1334            Expression::Literal(lit) => write!(f, "{}", lit),
1335            Expression::Identifier(id) => write!(f, "{}", id),
1336            Expression::Column(col) => write!(f, "{}", col),
1337            Expression::Star(_) => write!(f, "*"),
1338            Expression::Null(_) => write!(f, "NULL"),
1339            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1340            Expression::Select(_) => write!(f, "SELECT ..."),
1341            _ => write!(f, "{:?}", self),
1342        }
1343    }
1344}
1345
1346/// Represent a SQL literal value.
1347///
1348/// Numeric values are stored as their original text representation (not parsed
1349/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1350/// preserved across round-trips.
1351///
1352/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1353/// strings, raw strings, etc.) each have a dedicated variant so that the
1354/// generator can emit them with the correct syntax.
1355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1356#[cfg_attr(feature = "bindings", derive(TS))]
1357#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1358pub enum Literal {
1359    /// Single-quoted string literal: `'hello'`
1360    String(String),
1361    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1362    Number(String),
1363    /// Hex string literal: `X'FF'`
1364    HexString(String),
1365    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1366    HexNumber(String),
1367    BitString(String),
1368    /// Byte string: b"..." (BigQuery style)
1369    ByteString(String),
1370    /// National string: N'abc'
1371    NationalString(String),
1372    /// DATE literal: DATE '2024-01-15'
1373    Date(String),
1374    /// TIME literal: TIME '10:30:00'
1375    Time(String),
1376    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1377    Timestamp(String),
1378    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1379    Datetime(String),
1380    /// Triple-quoted string: """...""" or '''...'''
1381    /// Contains (content, quote_char) where quote_char is '"' or '\''
1382    TripleQuotedString(String, char),
1383    /// Escape string: E'...' (PostgreSQL)
1384    EscapeString(String),
1385    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1386    DollarString(String),
1387    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1388    /// In raw strings, backslashes are literal and not escape characters.
1389    /// When converting to a regular string, backslashes must be doubled.
1390    RawString(String),
1391}
1392
1393impl fmt::Display for Literal {
1394    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1395        match self {
1396            Literal::String(s) => write!(f, "'{}'", s),
1397            Literal::Number(n) => write!(f, "{}", n),
1398            Literal::HexString(h) => write!(f, "X'{}'", h),
1399            Literal::HexNumber(h) => write!(f, "0x{}", h),
1400            Literal::BitString(b) => write!(f, "B'{}'", b),
1401            Literal::ByteString(b) => write!(f, "b'{}'", b),
1402            Literal::NationalString(s) => write!(f, "N'{}'", s),
1403            Literal::Date(d) => write!(f, "DATE '{}'", d),
1404            Literal::Time(t) => write!(f, "TIME '{}'", t),
1405            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1406            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1407            Literal::TripleQuotedString(s, q) => {
1408                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1409            }
1410            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1411            Literal::DollarString(s) => write!(f, "$${}$$", s),
1412            Literal::RawString(s) => write!(f, "r'{}'", s),
1413        }
1414    }
1415}
1416
1417/// Boolean literal
1418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1419#[cfg_attr(feature = "bindings", derive(TS))]
1420pub struct BooleanLiteral {
1421    pub value: bool,
1422}
1423
1424/// NULL literal
1425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1426#[cfg_attr(feature = "bindings", derive(TS))]
1427pub struct Null;
1428
1429/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1430///
1431/// The `quoted` flag indicates whether the identifier was originally delimited
1432/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1433/// dialect). The generator uses this flag to decide whether to emit quoting
1434/// characters.
1435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1436#[cfg_attr(feature = "bindings", derive(TS))]
1437pub struct Identifier {
1438    /// The raw text of the identifier, without any quoting characters.
1439    pub name: String,
1440    /// Whether the identifier was quoted in the source SQL.
1441    pub quoted: bool,
1442    #[serde(default)]
1443    pub trailing_comments: Vec<String>,
1444    /// Source position span (populated during parsing, None for programmatically constructed nodes)
1445    #[serde(default, skip_serializing_if = "Option::is_none")]
1446    pub span: Option<Span>,
1447}
1448
1449impl Identifier {
1450    pub fn new(name: impl Into<String>) -> Self {
1451        Self {
1452            name: name.into(),
1453            quoted: false,
1454            trailing_comments: Vec::new(),
1455            span: None,
1456        }
1457    }
1458
1459    pub fn quoted(name: impl Into<String>) -> Self {
1460        Self {
1461            name: name.into(),
1462            quoted: true,
1463            trailing_comments: Vec::new(),
1464            span: None,
1465        }
1466    }
1467
1468    pub fn empty() -> Self {
1469        Self {
1470            name: String::new(),
1471            quoted: false,
1472            trailing_comments: Vec::new(),
1473            span: None,
1474        }
1475    }
1476
1477    pub fn is_empty(&self) -> bool {
1478        self.name.is_empty()
1479    }
1480
1481    /// Set the source span on this identifier
1482    pub fn with_span(mut self, span: Span) -> Self {
1483        self.span = Some(span);
1484        self
1485    }
1486}
1487
1488impl fmt::Display for Identifier {
1489    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1490        if self.quoted {
1491            write!(f, "\"{}\"", self.name)
1492        } else {
1493            write!(f, "{}", self.name)
1494        }
1495    }
1496}
1497
1498/// Represent a column reference, optionally qualified by a table name.
1499///
1500/// Renders as `name` when unqualified, or `table.name` when qualified.
1501/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1502/// convenient construction.
1503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1504#[cfg_attr(feature = "bindings", derive(TS))]
1505pub struct Column {
1506    /// The column name.
1507    pub name: Identifier,
1508    /// Optional table qualifier (e.g. `t` in `t.col`).
1509    pub table: Option<Identifier>,
1510    /// Oracle-style join marker (+) for outer joins
1511    #[serde(default)]
1512    pub join_mark: bool,
1513    /// Trailing comments that appeared after this column reference
1514    #[serde(default)]
1515    pub trailing_comments: Vec<String>,
1516    /// Source position span
1517    #[serde(default, skip_serializing_if = "Option::is_none")]
1518    pub span: Option<Span>,
1519}
1520
1521impl fmt::Display for Column {
1522    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1523        if let Some(table) = &self.table {
1524            write!(f, "{}.{}", table, self.name)
1525        } else {
1526            write!(f, "{}", self.name)
1527        }
1528    }
1529}
1530
1531/// Represent a table reference with optional schema and catalog qualifiers.
1532///
1533/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1534/// which qualifiers are present. Supports aliases, column alias lists,
1535/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1536/// several other dialect-specific extensions.
1537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1538#[cfg_attr(feature = "bindings", derive(TS))]
1539pub struct TableRef {
1540    /// The unqualified table name.
1541    pub name: Identifier,
1542    /// Optional schema qualifier (e.g. `public` in `public.users`).
1543    pub schema: Option<Identifier>,
1544    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
1545    pub catalog: Option<Identifier>,
1546    /// Optional table alias (e.g. `t` in `FROM users AS t`).
1547    pub alias: Option<Identifier>,
1548    /// Whether AS keyword was explicitly used for the alias
1549    #[serde(default)]
1550    pub alias_explicit_as: bool,
1551    /// Column aliases for table alias: AS t(c1, c2)
1552    #[serde(default)]
1553    pub column_aliases: Vec<Identifier>,
1554    /// Trailing comments that appeared after this table reference
1555    #[serde(default)]
1556    pub trailing_comments: Vec<String>,
1557    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
1558    #[serde(default)]
1559    pub when: Option<Box<HistoricalData>>,
1560    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
1561    #[serde(default)]
1562    pub only: bool,
1563    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
1564    #[serde(default)]
1565    pub final_: bool,
1566    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
1567    #[serde(default, skip_serializing_if = "Option::is_none")]
1568    pub table_sample: Option<Box<Sample>>,
1569    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
1570    #[serde(default)]
1571    pub hints: Vec<Expression>,
1572    /// TSQL: FOR SYSTEM_TIME temporal clause
1573    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
1574    #[serde(default, skip_serializing_if = "Option::is_none")]
1575    pub system_time: Option<String>,
1576    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
1577    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1578    pub partitions: Vec<Identifier>,
1579    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
1580    /// When set, this is used instead of the name field
1581    #[serde(default, skip_serializing_if = "Option::is_none")]
1582    pub identifier_func: Option<Box<Expression>>,
1583    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
1584    #[serde(default, skip_serializing_if = "Option::is_none")]
1585    pub changes: Option<Box<Changes>>,
1586    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
1587    #[serde(default, skip_serializing_if = "Option::is_none")]
1588    pub version: Option<Box<Version>>,
1589    /// Source position span
1590    #[serde(default, skip_serializing_if = "Option::is_none")]
1591    pub span: Option<Span>,
1592}
1593
1594impl TableRef {
1595    pub fn new(name: impl Into<String>) -> Self {
1596        Self {
1597            name: Identifier::new(name),
1598            schema: None,
1599            catalog: None,
1600            alias: None,
1601            alias_explicit_as: false,
1602            column_aliases: Vec::new(),
1603            trailing_comments: Vec::new(),
1604            when: None,
1605            only: false,
1606            final_: false,
1607            table_sample: None,
1608            hints: Vec::new(),
1609            system_time: None,
1610            partitions: Vec::new(),
1611            identifier_func: None,
1612            changes: None,
1613            version: None,
1614            span: None,
1615        }
1616    }
1617
1618    /// Create with a schema qualifier.
1619    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
1620        let mut t = Self::new(name);
1621        t.schema = Some(Identifier::new(schema));
1622        t
1623    }
1624
1625    /// Create with catalog and schema qualifiers.
1626    pub fn new_with_catalog(
1627        name: impl Into<String>,
1628        schema: impl Into<String>,
1629        catalog: impl Into<String>,
1630    ) -> Self {
1631        let mut t = Self::new(name);
1632        t.schema = Some(Identifier::new(schema));
1633        t.catalog = Some(Identifier::new(catalog));
1634        t
1635    }
1636
1637    /// Create from an Identifier, preserving the quoted flag
1638    pub fn from_identifier(name: Identifier) -> Self {
1639        Self {
1640            name,
1641            schema: None,
1642            catalog: None,
1643            alias: None,
1644            alias_explicit_as: false,
1645            column_aliases: Vec::new(),
1646            trailing_comments: Vec::new(),
1647            when: None,
1648            only: false,
1649            final_: false,
1650            table_sample: None,
1651            hints: Vec::new(),
1652            system_time: None,
1653            partitions: Vec::new(),
1654            identifier_func: None,
1655            changes: None,
1656            version: None,
1657            span: None,
1658        }
1659    }
1660
1661    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
1662        self.alias = Some(Identifier::new(alias));
1663        self
1664    }
1665
1666    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
1667        self.schema = Some(Identifier::new(schema));
1668        self
1669    }
1670}
1671
1672/// Represent a wildcard star expression (`*`, `table.*`).
1673///
1674/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
1675/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
1676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1677#[cfg_attr(feature = "bindings", derive(TS))]
1678pub struct Star {
1679    /// Optional table qualifier (e.g. `t` in `t.*`).
1680    pub table: Option<Identifier>,
1681    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
1682    pub except: Option<Vec<Identifier>>,
1683    /// REPLACE expressions (BigQuery, Snowflake)
1684    pub replace: Option<Vec<Alias>>,
1685    /// RENAME columns (Snowflake)
1686    pub rename: Option<Vec<(Identifier, Identifier)>>,
1687    /// Trailing comments that appeared after the star
1688    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1689    pub trailing_comments: Vec<String>,
1690    /// Source position span
1691    #[serde(default, skip_serializing_if = "Option::is_none")]
1692    pub span: Option<Span>,
1693}
1694
1695/// Represent a complete SELECT statement.
1696///
1697/// This is the most feature-rich AST node, covering the full surface area of
1698/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
1699/// `Vec` are omitted from the generated SQL when absent.
1700///
1701/// # Key Fields
1702///
1703/// - `expressions` -- the select-list (columns, `*`, computed expressions).
1704/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
1705/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
1706/// - `where_clause` -- the WHERE predicate.
1707/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
1708/// - `having` -- HAVING predicate.
1709/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
1710/// - `limit` / `offset` / `fetch` -- result set limiting.
1711/// - `with` -- Common Table Expressions (CTEs).
1712/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
1713/// - `windows` -- named window definitions (WINDOW w AS ...).
1714///
1715/// Dialect-specific extensions are supported via fields like `prewhere`
1716/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
1717/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
1718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1719#[cfg_attr(feature = "bindings", derive(TS))]
1720pub struct Select {
1721    /// The select-list: columns, expressions, aliases, and wildcards.
1722    pub expressions: Vec<Expression>,
1723    /// The FROM clause, containing one or more table sources.
1724    pub from: Option<From>,
1725    /// JOIN clauses applied after the FROM source.
1726    pub joins: Vec<Join>,
1727    pub lateral_views: Vec<LateralView>,
1728    /// ClickHouse PREWHERE clause
1729    #[serde(default, skip_serializing_if = "Option::is_none")]
1730    pub prewhere: Option<Expression>,
1731    pub where_clause: Option<Where>,
1732    pub group_by: Option<GroupBy>,
1733    pub having: Option<Having>,
1734    pub qualify: Option<Qualify>,
1735    pub order_by: Option<OrderBy>,
1736    pub distribute_by: Option<DistributeBy>,
1737    pub cluster_by: Option<ClusterBy>,
1738    pub sort_by: Option<SortBy>,
1739    pub limit: Option<Limit>,
1740    pub offset: Option<Offset>,
1741    /// ClickHouse LIMIT BY clause expressions
1742    #[serde(default, skip_serializing_if = "Option::is_none")]
1743    pub limit_by: Option<Vec<Expression>>,
1744    pub fetch: Option<Fetch>,
1745    pub distinct: bool,
1746    pub distinct_on: Option<Vec<Expression>>,
1747    pub top: Option<Top>,
1748    pub with: Option<With>,
1749    pub sample: Option<Sample>,
1750    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
1751    #[serde(default, skip_serializing_if = "Option::is_none")]
1752    pub settings: Option<Vec<Expression>>,
1753    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
1754    #[serde(default, skip_serializing_if = "Option::is_none")]
1755    pub format: Option<Expression>,
1756    pub windows: Option<Vec<NamedWindow>>,
1757    pub hint: Option<Hint>,
1758    /// Oracle CONNECT BY clause for hierarchical queries
1759    pub connect: Option<Connect>,
1760    /// SELECT ... INTO table_name for creating tables
1761    pub into: Option<SelectInto>,
1762    /// FOR UPDATE/SHARE locking clauses
1763    #[serde(default)]
1764    pub locks: Vec<Lock>,
1765    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
1766    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1767    pub for_xml: Vec<Expression>,
1768    /// Leading comments before the statement
1769    #[serde(default)]
1770    pub leading_comments: Vec<String>,
1771    /// Comments that appear after SELECT keyword (before expressions)
1772    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
1773    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1774    pub post_select_comments: Vec<String>,
1775    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
1776    #[serde(default, skip_serializing_if = "Option::is_none")]
1777    pub kind: Option<String>,
1778    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
1779    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1780    pub operation_modifiers: Vec<String>,
1781    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
1782    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1783    pub qualify_after_window: bool,
1784    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
1785    #[serde(default, skip_serializing_if = "Option::is_none")]
1786    pub option: Option<String>,
1787}
1788
1789impl Select {
1790    pub fn new() -> Self {
1791        Self {
1792            expressions: Vec::new(),
1793            from: None,
1794            joins: Vec::new(),
1795            lateral_views: Vec::new(),
1796            prewhere: None,
1797            where_clause: None,
1798            group_by: None,
1799            having: None,
1800            qualify: None,
1801            order_by: None,
1802            distribute_by: None,
1803            cluster_by: None,
1804            sort_by: None,
1805            limit: None,
1806            offset: None,
1807            limit_by: None,
1808            fetch: None,
1809            distinct: false,
1810            distinct_on: None,
1811            top: None,
1812            with: None,
1813            sample: None,
1814            settings: None,
1815            format: None,
1816            windows: None,
1817            hint: None,
1818            connect: None,
1819            into: None,
1820            locks: Vec::new(),
1821            for_xml: Vec::new(),
1822            leading_comments: Vec::new(),
1823            post_select_comments: Vec::new(),
1824            kind: None,
1825            operation_modifiers: Vec::new(),
1826            qualify_after_window: false,
1827            option: None,
1828        }
1829    }
1830
1831    /// Add a column to select
1832    pub fn column(mut self, expr: Expression) -> Self {
1833        self.expressions.push(expr);
1834        self
1835    }
1836
1837    /// Set the FROM clause
1838    pub fn from(mut self, table: Expression) -> Self {
1839        self.from = Some(From {
1840            expressions: vec![table],
1841        });
1842        self
1843    }
1844
1845    /// Add a WHERE clause
1846    pub fn where_(mut self, condition: Expression) -> Self {
1847        self.where_clause = Some(Where { this: condition });
1848        self
1849    }
1850
1851    /// Set DISTINCT
1852    pub fn distinct(mut self) -> Self {
1853        self.distinct = true;
1854        self
1855    }
1856
1857    /// Add a JOIN
1858    pub fn join(mut self, join: Join) -> Self {
1859        self.joins.push(join);
1860        self
1861    }
1862
1863    /// Set ORDER BY
1864    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
1865        self.order_by = Some(OrderBy {
1866            expressions,
1867            siblings: false,
1868            comments: Vec::new(),
1869        });
1870        self
1871    }
1872
1873    /// Set LIMIT
1874    pub fn limit(mut self, n: Expression) -> Self {
1875        self.limit = Some(Limit {
1876            this: n,
1877            percent: false,
1878            comments: Vec::new(),
1879        });
1880        self
1881    }
1882
1883    /// Set OFFSET
1884    pub fn offset(mut self, n: Expression) -> Self {
1885        self.offset = Some(Offset {
1886            this: n,
1887            rows: None,
1888        });
1889        self
1890    }
1891}
1892
1893impl Default for Select {
1894    fn default() -> Self {
1895        Self::new()
1896    }
1897}
1898
1899/// Represent a UNION set operation between two query expressions.
1900///
1901/// When `all` is true, duplicate rows are preserved (UNION ALL).
1902/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
1903/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
1904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1905#[cfg_attr(feature = "bindings", derive(TS))]
1906pub struct Union {
1907    /// The left-hand query operand.
1908    pub left: Expression,
1909    /// The right-hand query operand.
1910    pub right: Expression,
1911    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
1912    pub all: bool,
1913    /// Whether DISTINCT was explicitly specified
1914    #[serde(default)]
1915    pub distinct: bool,
1916    /// Optional WITH clause
1917    pub with: Option<With>,
1918    /// ORDER BY applied to entire UNION result
1919    pub order_by: Option<OrderBy>,
1920    /// LIMIT applied to entire UNION result
1921    pub limit: Option<Box<Expression>>,
1922    /// OFFSET applied to entire UNION result
1923    pub offset: Option<Box<Expression>>,
1924    /// DISTRIBUTE BY clause (Hive/Spark)
1925    #[serde(default, skip_serializing_if = "Option::is_none")]
1926    pub distribute_by: Option<DistributeBy>,
1927    /// SORT BY clause (Hive/Spark)
1928    #[serde(default, skip_serializing_if = "Option::is_none")]
1929    pub sort_by: Option<SortBy>,
1930    /// CLUSTER BY clause (Hive/Spark)
1931    #[serde(default, skip_serializing_if = "Option::is_none")]
1932    pub cluster_by: Option<ClusterBy>,
1933    /// DuckDB BY NAME modifier
1934    #[serde(default)]
1935    pub by_name: bool,
1936    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1937    #[serde(default, skip_serializing_if = "Option::is_none")]
1938    pub side: Option<String>,
1939    /// BigQuery: Set operation kind (INNER)
1940    #[serde(default, skip_serializing_if = "Option::is_none")]
1941    pub kind: Option<String>,
1942    /// BigQuery: CORRESPONDING modifier
1943    #[serde(default)]
1944    pub corresponding: bool,
1945    /// BigQuery: STRICT modifier (before CORRESPONDING)
1946    #[serde(default)]
1947    pub strict: bool,
1948    /// BigQuery: BY (columns) after CORRESPONDING
1949    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1950    pub on_columns: Vec<Expression>,
1951}
1952
1953/// Represent an INTERSECT set operation between two query expressions.
1954///
1955/// Returns only rows that appear in both operands. When `all` is true,
1956/// duplicates are preserved according to their multiplicity.
1957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1958#[cfg_attr(feature = "bindings", derive(TS))]
1959pub struct Intersect {
1960    /// The left-hand query operand.
1961    pub left: Expression,
1962    /// The right-hand query operand.
1963    pub right: Expression,
1964    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
1965    pub all: bool,
1966    /// Whether DISTINCT was explicitly specified
1967    #[serde(default)]
1968    pub distinct: bool,
1969    /// Optional WITH clause
1970    pub with: Option<With>,
1971    /// ORDER BY applied to entire INTERSECT result
1972    pub order_by: Option<OrderBy>,
1973    /// LIMIT applied to entire INTERSECT result
1974    pub limit: Option<Box<Expression>>,
1975    /// OFFSET applied to entire INTERSECT result
1976    pub offset: Option<Box<Expression>>,
1977    /// DISTRIBUTE BY clause (Hive/Spark)
1978    #[serde(default, skip_serializing_if = "Option::is_none")]
1979    pub distribute_by: Option<DistributeBy>,
1980    /// SORT BY clause (Hive/Spark)
1981    #[serde(default, skip_serializing_if = "Option::is_none")]
1982    pub sort_by: Option<SortBy>,
1983    /// CLUSTER BY clause (Hive/Spark)
1984    #[serde(default, skip_serializing_if = "Option::is_none")]
1985    pub cluster_by: Option<ClusterBy>,
1986    /// DuckDB BY NAME modifier
1987    #[serde(default)]
1988    pub by_name: bool,
1989    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1990    #[serde(default, skip_serializing_if = "Option::is_none")]
1991    pub side: Option<String>,
1992    /// BigQuery: Set operation kind (INNER)
1993    #[serde(default, skip_serializing_if = "Option::is_none")]
1994    pub kind: Option<String>,
1995    /// BigQuery: CORRESPONDING modifier
1996    #[serde(default)]
1997    pub corresponding: bool,
1998    /// BigQuery: STRICT modifier (before CORRESPONDING)
1999    #[serde(default)]
2000    pub strict: bool,
2001    /// BigQuery: BY (columns) after CORRESPONDING
2002    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2003    pub on_columns: Vec<Expression>,
2004}
2005
2006/// Represent an EXCEPT (MINUS) set operation between two query expressions.
2007///
2008/// Returns rows from the left operand that do not appear in the right operand.
2009/// When `all` is true, duplicates are subtracted according to their multiplicity.
2010#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2011#[cfg_attr(feature = "bindings", derive(TS))]
2012pub struct Except {
2013    /// The left-hand query operand.
2014    pub left: Expression,
2015    /// The right-hand query operand (rows to subtract).
2016    pub right: Expression,
2017    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
2018    pub all: bool,
2019    /// Whether DISTINCT was explicitly specified
2020    #[serde(default)]
2021    pub distinct: bool,
2022    /// Optional WITH clause
2023    pub with: Option<With>,
2024    /// ORDER BY applied to entire EXCEPT result
2025    pub order_by: Option<OrderBy>,
2026    /// LIMIT applied to entire EXCEPT result
2027    pub limit: Option<Box<Expression>>,
2028    /// OFFSET applied to entire EXCEPT result
2029    pub offset: Option<Box<Expression>>,
2030    /// DISTRIBUTE BY clause (Hive/Spark)
2031    #[serde(default, skip_serializing_if = "Option::is_none")]
2032    pub distribute_by: Option<DistributeBy>,
2033    /// SORT BY clause (Hive/Spark)
2034    #[serde(default, skip_serializing_if = "Option::is_none")]
2035    pub sort_by: Option<SortBy>,
2036    /// CLUSTER BY clause (Hive/Spark)
2037    #[serde(default, skip_serializing_if = "Option::is_none")]
2038    pub cluster_by: Option<ClusterBy>,
2039    /// DuckDB BY NAME modifier
2040    #[serde(default)]
2041    pub by_name: bool,
2042    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2043    #[serde(default, skip_serializing_if = "Option::is_none")]
2044    pub side: Option<String>,
2045    /// BigQuery: Set operation kind (INNER)
2046    #[serde(default, skip_serializing_if = "Option::is_none")]
2047    pub kind: Option<String>,
2048    /// BigQuery: CORRESPONDING modifier
2049    #[serde(default)]
2050    pub corresponding: bool,
2051    /// BigQuery: STRICT modifier (before CORRESPONDING)
2052    #[serde(default)]
2053    pub strict: bool,
2054    /// BigQuery: BY (columns) after CORRESPONDING
2055    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2056    pub on_columns: Vec<Expression>,
2057}
2058
2059/// INTO clause for SELECT INTO statements
2060#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2061#[cfg_attr(feature = "bindings", derive(TS))]
2062pub struct SelectInto {
2063    /// Target table or variable (used when single target)
2064    pub this: Expression,
2065    /// Whether TEMPORARY keyword was used
2066    #[serde(default)]
2067    pub temporary: bool,
2068    /// Whether UNLOGGED keyword was used (PostgreSQL)
2069    #[serde(default)]
2070    pub unlogged: bool,
2071    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2072    #[serde(default)]
2073    pub bulk_collect: bool,
2074    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2075    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2076    pub expressions: Vec<Expression>,
2077}
2078
2079/// Represent a parenthesized subquery expression.
2080///
2081/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2082/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2083/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2084/// modifiers are rendered inside or outside the parentheses.
2085///
2086/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2087/// scalar subqueries in select-lists, and derived tables.
2088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2089#[cfg_attr(feature = "bindings", derive(TS))]
2090pub struct Subquery {
2091    /// The inner query expression.
2092    pub this: Expression,
2093    /// Optional alias for the derived table.
2094    pub alias: Option<Identifier>,
2095    /// Optional column aliases: AS t(c1, c2)
2096    pub column_aliases: Vec<Identifier>,
2097    /// ORDER BY clause (for parenthesized queries)
2098    pub order_by: Option<OrderBy>,
2099    /// LIMIT clause
2100    pub limit: Option<Limit>,
2101    /// OFFSET clause
2102    pub offset: Option<Offset>,
2103    /// DISTRIBUTE BY clause (Hive/Spark)
2104    #[serde(default, skip_serializing_if = "Option::is_none")]
2105    pub distribute_by: Option<DistributeBy>,
2106    /// SORT BY clause (Hive/Spark)
2107    #[serde(default, skip_serializing_if = "Option::is_none")]
2108    pub sort_by: Option<SortBy>,
2109    /// CLUSTER BY clause (Hive/Spark)
2110    #[serde(default, skip_serializing_if = "Option::is_none")]
2111    pub cluster_by: Option<ClusterBy>,
2112    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2113    #[serde(default)]
2114    pub lateral: bool,
2115    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2116    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2117    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2118    #[serde(default)]
2119    pub modifiers_inside: bool,
2120    /// Trailing comments after the closing paren
2121    #[serde(default)]
2122    pub trailing_comments: Vec<String>,
2123}
2124
2125/// Pipe operator expression: query |> transform
2126///
2127/// Used in DataFusion and BigQuery pipe syntax:
2128///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2130#[cfg_attr(feature = "bindings", derive(TS))]
2131pub struct PipeOperator {
2132    /// The input query/expression (left side of |>)
2133    pub this: Expression,
2134    /// The piped operation (right side of |>)
2135    pub expression: Expression,
2136}
2137
2138/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2140#[cfg_attr(feature = "bindings", derive(TS))]
2141pub struct Values {
2142    /// The rows of values
2143    pub expressions: Vec<Tuple>,
2144    /// Optional alias for the table
2145    pub alias: Option<Identifier>,
2146    /// Optional column aliases: AS t(c1, c2)
2147    pub column_aliases: Vec<Identifier>,
2148}
2149
2150/// PIVOT operation - supports both standard and DuckDB simplified syntax
2151///
2152/// Standard syntax (in FROM clause):
2153///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2154///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2155///
2156/// DuckDB simplified syntax (statement-level):
2157///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2158///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2160#[cfg_attr(feature = "bindings", derive(TS))]
2161pub struct Pivot {
2162    /// Source table/expression
2163    pub this: Expression,
2164    /// For standard PIVOT: the aggregation function(s) (first is primary)
2165    /// For DuckDB simplified: unused (use `using` instead)
2166    #[serde(default)]
2167    pub expressions: Vec<Expression>,
2168    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2169    #[serde(default)]
2170    pub fields: Vec<Expression>,
2171    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2172    #[serde(default)]
2173    pub using: Vec<Expression>,
2174    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2175    #[serde(default)]
2176    pub group: Option<Box<Expression>>,
2177    /// Whether this is an UNPIVOT (vs PIVOT)
2178    #[serde(default)]
2179    pub unpivot: bool,
2180    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2181    #[serde(default)]
2182    pub into: Option<Box<Expression>>,
2183    /// Optional alias
2184    #[serde(default)]
2185    pub alias: Option<Identifier>,
2186    /// Include/exclude nulls (for UNPIVOT)
2187    #[serde(default)]
2188    pub include_nulls: Option<bool>,
2189    /// Default on null value (Snowflake)
2190    #[serde(default)]
2191    pub default_on_null: Option<Box<Expression>>,
2192    /// WITH clause (CTEs)
2193    #[serde(default, skip_serializing_if = "Option::is_none")]
2194    pub with: Option<With>,
2195}
2196
2197/// UNPIVOT operation
2198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2199#[cfg_attr(feature = "bindings", derive(TS))]
2200pub struct Unpivot {
2201    pub this: Expression,
2202    pub value_column: Identifier,
2203    pub name_column: Identifier,
2204    pub columns: Vec<Expression>,
2205    pub alias: Option<Identifier>,
2206    /// Whether the value_column was parenthesized in the original SQL
2207    #[serde(default)]
2208    pub value_column_parenthesized: bool,
2209    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2210    #[serde(default)]
2211    pub include_nulls: Option<bool>,
2212    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2213    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2214    pub extra_value_columns: Vec<Identifier>,
2215}
2216
2217/// PIVOT alias for aliasing pivot expressions
2218/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2220#[cfg_attr(feature = "bindings", derive(TS))]
2221pub struct PivotAlias {
2222    pub this: Expression,
2223    pub alias: Expression,
2224}
2225
2226/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2228#[cfg_attr(feature = "bindings", derive(TS))]
2229pub struct PreWhere {
2230    pub this: Expression,
2231}
2232
2233/// STREAM definition (Snowflake) - for change data capture
2234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2235#[cfg_attr(feature = "bindings", derive(TS))]
2236pub struct Stream {
2237    pub this: Expression,
2238    #[serde(skip_serializing_if = "Option::is_none")]
2239    pub on: Option<Expression>,
2240    #[serde(skip_serializing_if = "Option::is_none")]
2241    pub show_initial_rows: Option<bool>,
2242}
2243
2244/// USING DATA clause for data import statements
2245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2246#[cfg_attr(feature = "bindings", derive(TS))]
2247pub struct UsingData {
2248    pub this: Expression,
2249}
2250
2251/// XML Namespace declaration
2252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2253#[cfg_attr(feature = "bindings", derive(TS))]
2254pub struct XmlNamespace {
2255    pub this: Expression,
2256    #[serde(skip_serializing_if = "Option::is_none")]
2257    pub alias: Option<Identifier>,
2258}
2259
2260/// ROW FORMAT clause for Hive/Spark
2261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2262#[cfg_attr(feature = "bindings", derive(TS))]
2263pub struct RowFormat {
2264    pub delimited: bool,
2265    pub fields_terminated_by: Option<String>,
2266    pub collection_items_terminated_by: Option<String>,
2267    pub map_keys_terminated_by: Option<String>,
2268    pub lines_terminated_by: Option<String>,
2269    pub null_defined_as: Option<String>,
2270}
2271
2272/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2274#[cfg_attr(feature = "bindings", derive(TS))]
2275pub struct DirectoryInsert {
2276    pub local: bool,
2277    pub path: String,
2278    pub row_format: Option<RowFormat>,
2279    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2280    #[serde(default)]
2281    pub stored_as: Option<String>,
2282}
2283
2284/// INSERT statement
2285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2286#[cfg_attr(feature = "bindings", derive(TS))]
2287pub struct Insert {
2288    pub table: TableRef,
2289    pub columns: Vec<Identifier>,
2290    pub values: Vec<Vec<Expression>>,
2291    pub query: Option<Expression>,
2292    /// INSERT OVERWRITE for Hive/Spark
2293    pub overwrite: bool,
2294    /// PARTITION clause for Hive/Spark
2295    pub partition: Vec<(Identifier, Option<Expression>)>,
2296    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2297    #[serde(default)]
2298    pub directory: Option<DirectoryInsert>,
2299    /// RETURNING clause (PostgreSQL, SQLite)
2300    #[serde(default)]
2301    pub returning: Vec<Expression>,
2302    /// OUTPUT clause (TSQL)
2303    #[serde(default)]
2304    pub output: Option<OutputClause>,
2305    /// ON CONFLICT clause (PostgreSQL, SQLite)
2306    #[serde(default)]
2307    pub on_conflict: Option<Box<Expression>>,
2308    /// Leading comments before the statement
2309    #[serde(default)]
2310    pub leading_comments: Vec<String>,
2311    /// IF EXISTS clause (Hive)
2312    #[serde(default)]
2313    pub if_exists: bool,
2314    /// WITH clause (CTEs)
2315    #[serde(default)]
2316    pub with: Option<With>,
2317    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2318    #[serde(default)]
2319    pub ignore: bool,
2320    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2321    #[serde(default)]
2322    pub source_alias: Option<Identifier>,
2323    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2324    #[serde(default)]
2325    pub alias: Option<Identifier>,
2326    /// Whether the alias uses explicit AS keyword
2327    #[serde(default)]
2328    pub alias_explicit_as: bool,
2329    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2330    #[serde(default)]
2331    pub default_values: bool,
2332    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2333    #[serde(default)]
2334    pub by_name: bool,
2335    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2336    #[serde(default, skip_serializing_if = "Option::is_none")]
2337    pub conflict_action: Option<String>,
2338    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2339    #[serde(default)]
2340    pub is_replace: bool,
2341    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
2342    #[serde(default, skip_serializing_if = "Option::is_none")]
2343    pub hint: Option<Hint>,
2344    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2345    #[serde(default)]
2346    pub replace_where: Option<Box<Expression>>,
2347    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2348    #[serde(default)]
2349    pub source: Option<Box<Expression>>,
2350    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2351    #[serde(default, skip_serializing_if = "Option::is_none")]
2352    pub function_target: Option<Box<Expression>>,
2353    /// ClickHouse: PARTITION BY expr
2354    #[serde(default, skip_serializing_if = "Option::is_none")]
2355    pub partition_by: Option<Box<Expression>>,
2356    /// ClickHouse: SETTINGS key = val, ...
2357    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2358    pub settings: Vec<Expression>,
2359}
2360
2361/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2363#[cfg_attr(feature = "bindings", derive(TS))]
2364pub struct OutputClause {
2365    /// Columns/expressions to output
2366    pub columns: Vec<Expression>,
2367    /// Optional INTO target table or table variable
2368    #[serde(default)]
2369    pub into_table: Option<Expression>,
2370}
2371
2372/// UPDATE statement
2373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2374#[cfg_attr(feature = "bindings", derive(TS))]
2375pub struct Update {
2376    pub table: TableRef,
2377    /// Additional tables for multi-table UPDATE (MySQL syntax)
2378    #[serde(default)]
2379    pub extra_tables: Vec<TableRef>,
2380    /// JOINs attached to the table list (MySQL multi-table syntax)
2381    #[serde(default)]
2382    pub table_joins: Vec<Join>,
2383    pub set: Vec<(Identifier, Expression)>,
2384    pub from_clause: Option<From>,
2385    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2386    #[serde(default)]
2387    pub from_joins: Vec<Join>,
2388    pub where_clause: Option<Where>,
2389    /// RETURNING clause (PostgreSQL, SQLite)
2390    #[serde(default)]
2391    pub returning: Vec<Expression>,
2392    /// OUTPUT clause (TSQL)
2393    #[serde(default)]
2394    pub output: Option<OutputClause>,
2395    /// WITH clause (CTEs)
2396    #[serde(default)]
2397    pub with: Option<With>,
2398    /// Leading comments before the statement
2399    #[serde(default)]
2400    pub leading_comments: Vec<String>,
2401    /// LIMIT clause (MySQL)
2402    #[serde(default)]
2403    pub limit: Option<Expression>,
2404    /// ORDER BY clause (MySQL)
2405    #[serde(default)]
2406    pub order_by: Option<OrderBy>,
2407    /// Whether FROM clause appears before SET (Snowflake syntax)
2408    #[serde(default)]
2409    pub from_before_set: bool,
2410}
2411
2412/// DELETE statement
2413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2414#[cfg_attr(feature = "bindings", derive(TS))]
2415pub struct Delete {
2416    pub table: TableRef,
2417    /// ClickHouse: ON CLUSTER clause for distributed DDL
2418    #[serde(default, skip_serializing_if = "Option::is_none")]
2419    pub on_cluster: Option<OnCluster>,
2420    /// Optional alias for the table
2421    pub alias: Option<Identifier>,
2422    /// Whether the alias was declared with explicit AS keyword
2423    #[serde(default)]
2424    pub alias_explicit_as: bool,
2425    /// PostgreSQL/DuckDB USING clause - additional tables to join
2426    pub using: Vec<TableRef>,
2427    pub where_clause: Option<Where>,
2428    /// OUTPUT clause (TSQL)
2429    #[serde(default)]
2430    pub output: Option<OutputClause>,
2431    /// Leading comments before the statement
2432    #[serde(default)]
2433    pub leading_comments: Vec<String>,
2434    /// WITH clause (CTEs)
2435    #[serde(default)]
2436    pub with: Option<With>,
2437    /// LIMIT clause (MySQL)
2438    #[serde(default)]
2439    pub limit: Option<Expression>,
2440    /// ORDER BY clause (MySQL)
2441    #[serde(default)]
2442    pub order_by: Option<OrderBy>,
2443    /// RETURNING clause (PostgreSQL)
2444    #[serde(default)]
2445    pub returning: Vec<Expression>,
2446    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2447    /// These are the target tables to delete from
2448    #[serde(default)]
2449    pub tables: Vec<TableRef>,
2450    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2451    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2452    #[serde(default)]
2453    pub tables_from_using: bool,
2454    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2455    #[serde(default)]
2456    pub joins: Vec<Join>,
2457    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2458    #[serde(default)]
2459    pub force_index: Option<String>,
2460    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2461    #[serde(default)]
2462    pub no_from: bool,
2463}
2464
2465/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2467#[cfg_attr(feature = "bindings", derive(TS))]
2468pub struct CopyStmt {
2469    /// Target table or query
2470    pub this: Expression,
2471    /// True for FROM (loading into table), false for TO (exporting)
2472    pub kind: bool,
2473    /// Source/destination file(s) or stage
2474    pub files: Vec<Expression>,
2475    /// Copy parameters
2476    #[serde(default)]
2477    pub params: Vec<CopyParameter>,
2478    /// Credentials for external access
2479    #[serde(default)]
2480    pub credentials: Option<Box<Credentials>>,
2481    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2482    #[serde(default)]
2483    pub is_into: bool,
2484    /// Whether parameters are wrapped in WITH (...) syntax
2485    #[serde(default)]
2486    pub with_wrapped: bool,
2487}
2488
2489/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2491#[cfg_attr(feature = "bindings", derive(TS))]
2492pub struct CopyParameter {
2493    pub name: String,
2494    pub value: Option<Expression>,
2495    pub values: Vec<Expression>,
2496    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2497    #[serde(default)]
2498    pub eq: bool,
2499}
2500
2501/// Credentials for external access (S3, Azure, etc.)
2502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2503#[cfg_attr(feature = "bindings", derive(TS))]
2504pub struct Credentials {
2505    pub credentials: Vec<(String, String)>,
2506    pub encryption: Option<String>,
2507    pub storage: Option<String>,
2508}
2509
2510/// PUT statement (Snowflake)
2511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2512#[cfg_attr(feature = "bindings", derive(TS))]
2513pub struct PutStmt {
2514    /// Source file path
2515    pub source: String,
2516    /// Whether source was quoted in the original SQL
2517    #[serde(default)]
2518    pub source_quoted: bool,
2519    /// Target stage
2520    pub target: Expression,
2521    /// PUT parameters
2522    #[serde(default)]
2523    pub params: Vec<CopyParameter>,
2524}
2525
2526/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2528#[cfg_attr(feature = "bindings", derive(TS))]
2529pub struct StageReference {
2530    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2531    pub name: String,
2532    /// Optional path within the stage (e.g., "/path/to/file.csv")
2533    #[serde(default)]
2534    pub path: Option<String>,
2535    /// Optional FILE_FORMAT parameter
2536    #[serde(default)]
2537    pub file_format: Option<Expression>,
2538    /// Optional PATTERN parameter
2539    #[serde(default)]
2540    pub pattern: Option<String>,
2541    /// Whether the stage reference was originally quoted (e.g., '@mystage')
2542    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2543    pub quoted: bool,
2544}
2545
2546/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2548#[cfg_attr(feature = "bindings", derive(TS))]
2549pub struct HistoricalData {
2550    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
2551    pub this: Box<Expression>,
2552    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
2553    pub kind: String,
2554    /// The expression value (e.g., the statement ID or timestamp)
2555    pub expression: Box<Expression>,
2556}
2557
2558/// Represent an aliased expression (`expr AS name`).
2559///
2560/// Used for column aliases in select-lists, table aliases on subqueries,
2561/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
2562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2563#[cfg_attr(feature = "bindings", derive(TS))]
2564pub struct Alias {
2565    /// The expression being aliased.
2566    pub this: Expression,
2567    /// The alias name (required for simple aliases, optional when only column aliases provided)
2568    pub alias: Identifier,
2569    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
2570    #[serde(default)]
2571    pub column_aliases: Vec<Identifier>,
2572    /// Comments that appeared between the expression and AS keyword
2573    #[serde(default)]
2574    pub pre_alias_comments: Vec<String>,
2575    /// Trailing comments that appeared after the alias
2576    #[serde(default)]
2577    pub trailing_comments: Vec<String>,
2578}
2579
2580impl Alias {
2581    /// Create a simple alias
2582    pub fn new(this: Expression, alias: Identifier) -> Self {
2583        Self {
2584            this,
2585            alias,
2586            column_aliases: Vec::new(),
2587            pre_alias_comments: Vec::new(),
2588            trailing_comments: Vec::new(),
2589        }
2590    }
2591
2592    /// Create an alias with column aliases only (no table alias name)
2593    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
2594        Self {
2595            this,
2596            alias: Identifier::empty(),
2597            column_aliases,
2598            pre_alias_comments: Vec::new(),
2599            trailing_comments: Vec::new(),
2600        }
2601    }
2602}
2603
2604/// Represent a type cast expression.
2605///
2606/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
2607/// shorthand `expr::type`. Also used as the payload for `TryCast` and
2608/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
2609/// CONVERSION ERROR (Oracle) clauses.
2610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2611#[cfg_attr(feature = "bindings", derive(TS))]
2612pub struct Cast {
2613    /// The expression being cast.
2614    pub this: Expression,
2615    /// The target data type.
2616    pub to: DataType,
2617    #[serde(default)]
2618    pub trailing_comments: Vec<String>,
2619    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
2620    #[serde(default)]
2621    pub double_colon_syntax: bool,
2622    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
2623    #[serde(skip_serializing_if = "Option::is_none", default)]
2624    pub format: Option<Box<Expression>>,
2625    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
2626    #[serde(skip_serializing_if = "Option::is_none", default)]
2627    pub default: Option<Box<Expression>>,
2628}
2629
2630///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
2631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2632#[cfg_attr(feature = "bindings", derive(TS))]
2633pub struct CollationExpr {
2634    pub this: Expression,
2635    pub collation: String,
2636    /// True if the collation was single-quoted in the original SQL (string literal)
2637    #[serde(default)]
2638    pub quoted: bool,
2639    /// True if the collation was double-quoted in the original SQL (identifier)
2640    #[serde(default)]
2641    pub double_quoted: bool,
2642}
2643
2644/// Represent a CASE expression (both simple and searched forms).
2645///
2646/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
2647/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
2648/// Each entry in `whens` is a `(condition, result)` pair.
2649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2650#[cfg_attr(feature = "bindings", derive(TS))]
2651pub struct Case {
2652    /// The operand for simple CASE, or `None` for searched CASE.
2653    pub operand: Option<Expression>,
2654    /// Pairs of (WHEN condition, THEN result).
2655    pub whens: Vec<(Expression, Expression)>,
2656    /// Optional ELSE result.
2657    pub else_: Option<Expression>,
2658    /// Comments from the CASE keyword (emitted after END)
2659    #[serde(default)]
2660    #[serde(skip_serializing_if = "Vec::is_empty")]
2661    pub comments: Vec<String>,
2662}
2663
2664/// Represent a binary operation (two operands separated by an operator).
2665///
2666/// This is the shared payload struct for all binary operator variants in the
2667/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
2668/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
2669/// bitwise, and dialect-specific operators. Comment fields enable round-trip
2670/// preservation of inline comments around operators.
2671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2672#[cfg_attr(feature = "bindings", derive(TS))]
2673pub struct BinaryOp {
2674    pub left: Expression,
2675    pub right: Expression,
2676    /// Comments after the left operand (before the operator)
2677    #[serde(default)]
2678    pub left_comments: Vec<String>,
2679    /// Comments after the operator (before the right operand)
2680    #[serde(default)]
2681    pub operator_comments: Vec<String>,
2682    /// Comments after the right operand
2683    #[serde(default)]
2684    pub trailing_comments: Vec<String>,
2685}
2686
2687impl BinaryOp {
2688    pub fn new(left: Expression, right: Expression) -> Self {
2689        Self {
2690            left,
2691            right,
2692            left_comments: Vec::new(),
2693            operator_comments: Vec::new(),
2694            trailing_comments: Vec::new(),
2695        }
2696    }
2697}
2698
2699/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
2700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2701#[cfg_attr(feature = "bindings", derive(TS))]
2702pub struct LikeOp {
2703    pub left: Expression,
2704    pub right: Expression,
2705    /// ESCAPE character/expression
2706    #[serde(default)]
2707    pub escape: Option<Expression>,
2708    /// Quantifier: ANY, ALL, or SOME
2709    #[serde(default)]
2710    pub quantifier: Option<String>,
2711}
2712
2713impl LikeOp {
2714    pub fn new(left: Expression, right: Expression) -> Self {
2715        Self {
2716            left,
2717            right,
2718            escape: None,
2719            quantifier: None,
2720        }
2721    }
2722
2723    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
2724        Self {
2725            left,
2726            right,
2727            escape: Some(escape),
2728            quantifier: None,
2729        }
2730    }
2731}
2732
2733/// Represent a unary operation (single operand with a prefix operator).
2734///
2735/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
2736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2737#[cfg_attr(feature = "bindings", derive(TS))]
2738pub struct UnaryOp {
2739    /// The operand expression.
2740    pub this: Expression,
2741}
2742
2743impl UnaryOp {
2744    pub fn new(this: Expression) -> Self {
2745        Self { this }
2746    }
2747}
2748
2749/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
2750///
2751/// Either `expressions` (a value list) or `query` (a subquery) is populated,
2752/// but not both. When `not` is true, the predicate is `NOT IN`.
2753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2754#[cfg_attr(feature = "bindings", derive(TS))]
2755pub struct In {
2756    /// The expression being tested.
2757    pub this: Expression,
2758    /// The value list (mutually exclusive with `query`).
2759    pub expressions: Vec<Expression>,
2760    /// A subquery (mutually exclusive with `expressions`).
2761    pub query: Option<Expression>,
2762    /// Whether this is NOT IN.
2763    pub not: bool,
2764    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2765    pub global: bool,
2766    /// BigQuery: IN UNNEST(expr)
2767    #[serde(default, skip_serializing_if = "Option::is_none")]
2768    pub unnest: Option<Box<Expression>>,
2769    /// Whether the right side is a bare field reference (no parentheses).
2770    /// Matches Python sqlglot's `field` attribute on `In` expression.
2771    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
2772    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2773    pub is_field: bool,
2774}
2775
2776/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
2777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2778#[cfg_attr(feature = "bindings", derive(TS))]
2779pub struct Between {
2780    /// The expression being tested.
2781    pub this: Expression,
2782    /// The lower bound.
2783    pub low: Expression,
2784    /// The upper bound.
2785    pub high: Expression,
2786    /// Whether this is NOT BETWEEN.
2787    pub not: bool,
2788    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
2789    #[serde(default)]
2790    pub symmetric: Option<bool>,
2791}
2792
2793/// IS NULL predicate
2794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2795#[cfg_attr(feature = "bindings", derive(TS))]
2796pub struct IsNull {
2797    pub this: Expression,
2798    pub not: bool,
2799    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
2800    #[serde(default)]
2801    pub postfix_form: bool,
2802}
2803
2804/// IS TRUE / IS FALSE predicate
2805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2806#[cfg_attr(feature = "bindings", derive(TS))]
2807pub struct IsTrueFalse {
2808    pub this: Expression,
2809    pub not: bool,
2810}
2811
2812/// IS JSON predicate (SQL standard)
2813/// Checks if a value is valid JSON
2814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2815#[cfg_attr(feature = "bindings", derive(TS))]
2816pub struct IsJson {
2817    pub this: Expression,
2818    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
2819    pub json_type: Option<String>,
2820    /// Key uniqueness constraint
2821    pub unique_keys: Option<JsonUniqueKeys>,
2822    /// Whether IS NOT JSON
2823    pub negated: bool,
2824}
2825
2826/// JSON unique keys constraint variants
2827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2828#[cfg_attr(feature = "bindings", derive(TS))]
2829pub enum JsonUniqueKeys {
2830    /// WITH UNIQUE KEYS
2831    With,
2832    /// WITHOUT UNIQUE KEYS
2833    Without,
2834    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
2835    Shorthand,
2836}
2837
2838/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
2839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2840#[cfg_attr(feature = "bindings", derive(TS))]
2841pub struct Exists {
2842    /// The subquery expression.
2843    pub this: Expression,
2844    /// Whether this is NOT EXISTS.
2845    pub not: bool,
2846}
2847
2848/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
2849///
2850/// This is the generic function node. Well-known aggregates, window functions,
2851/// and built-in functions each have their own dedicated `Expression` variants
2852/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
2853/// not recognize as built-ins are represented with this struct.
2854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2855#[cfg_attr(feature = "bindings", derive(TS))]
2856pub struct Function {
2857    /// The function name, as originally written (may be schema-qualified).
2858    pub name: String,
2859    /// Positional arguments to the function.
2860    pub args: Vec<Expression>,
2861    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
2862    pub distinct: bool,
2863    #[serde(default)]
2864    pub trailing_comments: Vec<String>,
2865    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
2866    #[serde(default)]
2867    pub use_bracket_syntax: bool,
2868    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
2869    #[serde(default)]
2870    pub no_parens: bool,
2871    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
2872    #[serde(default)]
2873    pub quoted: bool,
2874    /// Source position span
2875    #[serde(default, skip_serializing_if = "Option::is_none")]
2876    pub span: Option<Span>,
2877}
2878
2879impl Default for Function {
2880    fn default() -> Self {
2881        Self {
2882            name: String::new(),
2883            args: Vec::new(),
2884            distinct: false,
2885            trailing_comments: Vec::new(),
2886            use_bracket_syntax: false,
2887            no_parens: false,
2888            quoted: false,
2889            span: None,
2890        }
2891    }
2892}
2893
2894impl Function {
2895    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
2896        Self {
2897            name: name.into(),
2898            args,
2899            distinct: false,
2900            trailing_comments: Vec::new(),
2901            use_bracket_syntax: false,
2902            no_parens: false,
2903            quoted: false,
2904            span: None,
2905        }
2906    }
2907}
2908
2909/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
2910///
2911/// This struct is used for aggregate function calls that are not covered by
2912/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
2913/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
2914/// IGNORE NULLS / RESPECT NULLS modifiers.
2915#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2916#[cfg_attr(feature = "bindings", derive(TS))]
2917pub struct AggregateFunction {
2918    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
2919    pub name: String,
2920    /// Positional arguments.
2921    pub args: Vec<Expression>,
2922    /// Whether DISTINCT was specified.
2923    pub distinct: bool,
2924    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
2925    pub filter: Option<Expression>,
2926    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
2927    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2928    pub order_by: Vec<Ordered>,
2929    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
2930    #[serde(default, skip_serializing_if = "Option::is_none")]
2931    pub limit: Option<Box<Expression>>,
2932    /// IGNORE NULLS / RESPECT NULLS
2933    #[serde(default, skip_serializing_if = "Option::is_none")]
2934    pub ignore_nulls: Option<bool>,
2935}
2936
2937/// Represent a window function call with its OVER clause.
2938///
2939/// The inner `this` expression is typically a window-specific expression
2940/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
2941/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
2942/// frame specification.
2943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2944#[cfg_attr(feature = "bindings", derive(TS))]
2945pub struct WindowFunction {
2946    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
2947    pub this: Expression,
2948    /// The OVER clause defining the window partitioning, ordering, and frame.
2949    pub over: Over,
2950    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
2951    #[serde(default, skip_serializing_if = "Option::is_none")]
2952    pub keep: Option<Keep>,
2953}
2954
2955/// Oracle KEEP clause for aggregate functions
2956/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
2957#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2958#[cfg_attr(feature = "bindings", derive(TS))]
2959pub struct Keep {
2960    /// true = FIRST, false = LAST
2961    pub first: bool,
2962    /// ORDER BY clause inside KEEP
2963    pub order_by: Vec<Ordered>,
2964}
2965
2966/// WITHIN GROUP clause (for ordered-set aggregate functions)
2967#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2968#[cfg_attr(feature = "bindings", derive(TS))]
2969pub struct WithinGroup {
2970    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
2971    pub this: Expression,
2972    /// The ORDER BY clause within the group
2973    pub order_by: Vec<Ordered>,
2974}
2975
2976/// Represent the FROM clause of a SELECT statement.
2977///
2978/// Contains one or more table sources (tables, subqueries, table-valued
2979/// functions, etc.). Multiple entries represent comma-separated implicit joins.
2980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2981#[cfg_attr(feature = "bindings", derive(TS))]
2982pub struct From {
2983    /// The table source expressions.
2984    pub expressions: Vec<Expression>,
2985}
2986
2987/// Represent a JOIN clause between two table sources.
2988///
2989/// The join condition can be specified via `on` (ON predicate) or `using`
2990/// (USING column list), but not both. The `kind` field determines the join
2991/// type (INNER, LEFT, CROSS, etc.).
2992#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2993#[cfg_attr(feature = "bindings", derive(TS))]
2994pub struct Join {
2995    /// The right-hand table expression being joined.
2996    pub this: Expression,
2997    /// The ON condition (mutually exclusive with `using`).
2998    pub on: Option<Expression>,
2999    /// The USING column list (mutually exclusive with `on`).
3000    pub using: Vec<Identifier>,
3001    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
3002    pub kind: JoinKind,
3003    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
3004    pub use_inner_keyword: bool,
3005    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
3006    pub use_outer_keyword: bool,
3007    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
3008    pub deferred_condition: bool,
3009    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
3010    #[serde(default, skip_serializing_if = "Option::is_none")]
3011    pub join_hint: Option<String>,
3012    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
3013    #[serde(default, skip_serializing_if = "Option::is_none")]
3014    pub match_condition: Option<Expression>,
3015    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
3016    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3017    pub pivots: Vec<Expression>,
3018    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
3019    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3020    pub comments: Vec<String>,
3021    /// Nesting group identifier for nested join pretty-printing.
3022    /// Joins in the same group were parsed together; group boundaries come from
3023    /// deferred condition resolution phases.
3024    #[serde(default)]
3025    pub nesting_group: usize,
3026    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
3027    #[serde(default)]
3028    pub directed: bool,
3029}
3030
3031/// Enumerate all supported SQL join types.
3032///
3033/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
3034/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3035/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3036/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3037#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3038#[cfg_attr(feature = "bindings", derive(TS))]
3039pub enum JoinKind {
3040    Inner,
3041    Left,
3042    Right,
3043    Full,
3044    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3045    Cross,
3046    Natural,
3047    NaturalLeft,
3048    NaturalRight,
3049    NaturalFull,
3050    Semi,
3051    Anti,
3052    // Directional SEMI/ANTI joins
3053    LeftSemi,
3054    LeftAnti,
3055    RightSemi,
3056    RightAnti,
3057    // SQL Server specific
3058    CrossApply,
3059    OuterApply,
3060    // Time-series specific
3061    AsOf,
3062    AsOfLeft,
3063    AsOfRight,
3064    // Lateral join
3065    Lateral,
3066    LeftLateral,
3067    // MySQL specific
3068    Straight,
3069    // Implicit join (comma-separated tables: FROM a, b)
3070    Implicit,
3071    // ClickHouse ARRAY JOIN
3072    Array,
3073    LeftArray,
3074    // ClickHouse PASTE JOIN (positional join)
3075    Paste,
3076}
3077
3078impl Default for JoinKind {
3079    fn default() -> Self {
3080        JoinKind::Inner
3081    }
3082}
3083
3084/// Parenthesized table expression with joins
3085/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3086#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3087#[cfg_attr(feature = "bindings", derive(TS))]
3088pub struct JoinedTable {
3089    /// The left-hand side table expression
3090    pub left: Expression,
3091    /// The joins applied to the left table
3092    pub joins: Vec<Join>,
3093    /// LATERAL VIEW clauses (Hive/Spark)
3094    pub lateral_views: Vec<LateralView>,
3095    /// Optional alias for the joined table expression
3096    pub alias: Option<Identifier>,
3097}
3098
3099/// Represent a WHERE clause containing a boolean filter predicate.
3100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3101#[cfg_attr(feature = "bindings", derive(TS))]
3102pub struct Where {
3103    /// The filter predicate expression.
3104    pub this: Expression,
3105}
3106
3107/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3108///
3109/// The `expressions` list may contain plain columns, ordinal positions,
3110/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3112#[cfg_attr(feature = "bindings", derive(TS))]
3113pub struct GroupBy {
3114    /// The grouping expressions.
3115    pub expressions: Vec<Expression>,
3116    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3117    #[serde(default)]
3118    pub all: Option<bool>,
3119    /// ClickHouse: WITH TOTALS modifier
3120    #[serde(default)]
3121    pub totals: bool,
3122    /// Leading comments that appeared before the GROUP BY keyword
3123    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3124    pub comments: Vec<String>,
3125}
3126
3127/// Represent a HAVING clause containing a predicate over aggregate results.
3128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3129#[cfg_attr(feature = "bindings", derive(TS))]
3130pub struct Having {
3131    /// The filter predicate, typically involving aggregate functions.
3132    pub this: Expression,
3133    /// Leading comments that appeared before the HAVING keyword
3134    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3135    pub comments: Vec<String>,
3136}
3137
3138/// Represent an ORDER BY clause containing one or more sort specifications.
3139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3140#[cfg_attr(feature = "bindings", derive(TS))]
3141pub struct OrderBy {
3142    /// The sort specifications, each with direction and null ordering.
3143    pub expressions: Vec<Ordered>,
3144    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3145    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3146    pub siblings: bool,
3147    /// Leading comments that appeared before the ORDER BY keyword
3148    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3149    pub comments: Vec<String>,
3150}
3151
3152/// Represent an expression with sort direction and null ordering.
3153///
3154/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3155/// When `desc` is false the sort is ascending. The `nulls_first` field
3156/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3157/// (database default).
3158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3159#[cfg_attr(feature = "bindings", derive(TS))]
3160pub struct Ordered {
3161    /// The expression to sort by.
3162    pub this: Expression,
3163    /// Whether the sort direction is descending (true) or ascending (false).
3164    pub desc: bool,
3165    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3166    pub nulls_first: Option<bool>,
3167    /// Whether ASC was explicitly written (not just implied)
3168    #[serde(default)]
3169    pub explicit_asc: bool,
3170    /// ClickHouse WITH FILL clause
3171    #[serde(default, skip_serializing_if = "Option::is_none")]
3172    pub with_fill: Option<Box<WithFill>>,
3173}
3174
3175impl Ordered {
3176    pub fn asc(expr: Expression) -> Self {
3177        Self {
3178            this: expr,
3179            desc: false,
3180            nulls_first: None,
3181            explicit_asc: false,
3182            with_fill: None,
3183        }
3184    }
3185
3186    pub fn desc(expr: Expression) -> Self {
3187        Self {
3188            this: expr,
3189            desc: true,
3190            nulls_first: None,
3191            explicit_asc: false,
3192            with_fill: None,
3193        }
3194    }
3195}
3196
3197/// DISTRIBUTE BY clause (Hive/Spark)
3198/// Controls how rows are distributed across reducers
3199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3200#[cfg_attr(feature = "bindings", derive(TS))]
3201#[cfg_attr(feature = "bindings", ts(export))]
3202pub struct DistributeBy {
3203    pub expressions: Vec<Expression>,
3204}
3205
3206/// CLUSTER BY clause (Hive/Spark)
3207/// Combines DISTRIBUTE BY and SORT BY on the same columns
3208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3209#[cfg_attr(feature = "bindings", derive(TS))]
3210#[cfg_attr(feature = "bindings", ts(export))]
3211pub struct ClusterBy {
3212    pub expressions: Vec<Ordered>,
3213}
3214
3215/// SORT BY clause (Hive/Spark)
3216/// Sorts data within each reducer (local sort, not global)
3217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3218#[cfg_attr(feature = "bindings", derive(TS))]
3219#[cfg_attr(feature = "bindings", ts(export))]
3220pub struct SortBy {
3221    pub expressions: Vec<Ordered>,
3222}
3223
3224/// LATERAL VIEW clause (Hive/Spark)
3225/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3227#[cfg_attr(feature = "bindings", derive(TS))]
3228#[cfg_attr(feature = "bindings", ts(export))]
3229pub struct LateralView {
3230    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3231    pub this: Expression,
3232    /// Table alias for the generated table
3233    pub table_alias: Option<Identifier>,
3234    /// Column aliases for the generated columns
3235    pub column_aliases: Vec<Identifier>,
3236    /// OUTER keyword - preserve nulls when input is empty/null
3237    pub outer: bool,
3238}
3239
3240/// Query hint
3241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3242#[cfg_attr(feature = "bindings", derive(TS))]
3243#[cfg_attr(feature = "bindings", ts(export))]
3244pub struct Hint {
3245    pub expressions: Vec<HintExpression>,
3246}
3247
3248/// Individual hint expression
3249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3250#[cfg_attr(feature = "bindings", derive(TS))]
3251#[cfg_attr(feature = "bindings", ts(export))]
3252pub enum HintExpression {
3253    /// Function-style hint: USE_HASH(table)
3254    Function { name: String, args: Vec<Expression> },
3255    /// Simple identifier hint: PARALLEL
3256    Identifier(String),
3257    /// Raw hint text (unparsed)
3258    Raw(String),
3259}
3260
3261/// Pseudocolumn type
3262#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3263#[cfg_attr(feature = "bindings", derive(TS))]
3264#[cfg_attr(feature = "bindings", ts(export))]
3265pub enum PseudocolumnType {
3266    Rownum,      // Oracle ROWNUM
3267    Rowid,       // Oracle ROWID
3268    Level,       // Oracle LEVEL (for CONNECT BY)
3269    Sysdate,     // Oracle SYSDATE
3270    ObjectId,    // Oracle OBJECT_ID
3271    ObjectValue, // Oracle OBJECT_VALUE
3272}
3273
3274impl PseudocolumnType {
3275    pub fn as_str(&self) -> &'static str {
3276        match self {
3277            PseudocolumnType::Rownum => "ROWNUM",
3278            PseudocolumnType::Rowid => "ROWID",
3279            PseudocolumnType::Level => "LEVEL",
3280            PseudocolumnType::Sysdate => "SYSDATE",
3281            PseudocolumnType::ObjectId => "OBJECT_ID",
3282            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3283        }
3284    }
3285
3286    pub fn from_str(s: &str) -> Option<Self> {
3287        match s.to_uppercase().as_str() {
3288            "ROWNUM" => Some(PseudocolumnType::Rownum),
3289            "ROWID" => Some(PseudocolumnType::Rowid),
3290            "LEVEL" => Some(PseudocolumnType::Level),
3291            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3292            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3293            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3294            _ => None,
3295        }
3296    }
3297}
3298
3299/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3300/// These are special identifiers that should not be quoted
3301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3302#[cfg_attr(feature = "bindings", derive(TS))]
3303#[cfg_attr(feature = "bindings", ts(export))]
3304pub struct Pseudocolumn {
3305    pub kind: PseudocolumnType,
3306}
3307
3308impl Pseudocolumn {
3309    pub fn rownum() -> Self {
3310        Self {
3311            kind: PseudocolumnType::Rownum,
3312        }
3313    }
3314
3315    pub fn rowid() -> Self {
3316        Self {
3317            kind: PseudocolumnType::Rowid,
3318        }
3319    }
3320
3321    pub fn level() -> Self {
3322        Self {
3323            kind: PseudocolumnType::Level,
3324        }
3325    }
3326}
3327
3328/// Oracle CONNECT BY clause for hierarchical queries
3329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3330#[cfg_attr(feature = "bindings", derive(TS))]
3331#[cfg_attr(feature = "bindings", ts(export))]
3332pub struct Connect {
3333    /// START WITH condition (optional, can come before or after CONNECT BY)
3334    pub start: Option<Expression>,
3335    /// CONNECT BY condition (required, contains PRIOR references)
3336    pub connect: Expression,
3337    /// NOCYCLE keyword to prevent infinite loops
3338    pub nocycle: bool,
3339}
3340
3341/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3343#[cfg_attr(feature = "bindings", derive(TS))]
3344#[cfg_attr(feature = "bindings", ts(export))]
3345pub struct Prior {
3346    pub this: Expression,
3347}
3348
3349/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3350#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3351#[cfg_attr(feature = "bindings", derive(TS))]
3352#[cfg_attr(feature = "bindings", ts(export))]
3353pub struct ConnectByRoot {
3354    pub this: Expression,
3355}
3356
3357/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3359#[cfg_attr(feature = "bindings", derive(TS))]
3360#[cfg_attr(feature = "bindings", ts(export))]
3361pub struct MatchRecognize {
3362    /// Source table/expression
3363    pub this: Option<Box<Expression>>,
3364    /// PARTITION BY expressions
3365    pub partition_by: Option<Vec<Expression>>,
3366    /// ORDER BY expressions
3367    pub order_by: Option<Vec<Ordered>>,
3368    /// MEASURES definitions
3369    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3370    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3371    pub rows: Option<MatchRecognizeRows>,
3372    /// AFTER MATCH SKIP behavior
3373    pub after: Option<MatchRecognizeAfter>,
3374    /// PATTERN definition (stored as raw string for complex regex patterns)
3375    pub pattern: Option<String>,
3376    /// DEFINE clauses (pattern variable definitions)
3377    pub define: Option<Vec<(Identifier, Expression)>>,
3378    /// Optional alias for the result
3379    pub alias: Option<Identifier>,
3380    /// Whether AS keyword was explicitly present before alias
3381    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3382    pub alias_explicit_as: bool,
3383}
3384
3385/// MEASURES expression with optional RUNNING/FINAL semantics
3386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3387#[cfg_attr(feature = "bindings", derive(TS))]
3388#[cfg_attr(feature = "bindings", ts(export))]
3389pub struct MatchRecognizeMeasure {
3390    /// The measure expression
3391    pub this: Expression,
3392    /// RUNNING or FINAL semantics (Snowflake-specific)
3393    pub window_frame: Option<MatchRecognizeSemantics>,
3394}
3395
3396/// Semantics for MEASURES in MATCH_RECOGNIZE
3397#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3398#[cfg_attr(feature = "bindings", derive(TS))]
3399#[cfg_attr(feature = "bindings", ts(export))]
3400pub enum MatchRecognizeSemantics {
3401    Running,
3402    Final,
3403}
3404
3405/// Row output semantics for MATCH_RECOGNIZE
3406#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3407#[cfg_attr(feature = "bindings", derive(TS))]
3408#[cfg_attr(feature = "bindings", ts(export))]
3409pub enum MatchRecognizeRows {
3410    OneRowPerMatch,
3411    AllRowsPerMatch,
3412    AllRowsPerMatchShowEmptyMatches,
3413    AllRowsPerMatchOmitEmptyMatches,
3414    AllRowsPerMatchWithUnmatchedRows,
3415}
3416
3417/// AFTER MATCH SKIP behavior
3418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3419#[cfg_attr(feature = "bindings", derive(TS))]
3420#[cfg_attr(feature = "bindings", ts(export))]
3421pub enum MatchRecognizeAfter {
3422    PastLastRow,
3423    ToNextRow,
3424    ToFirst(Identifier),
3425    ToLast(Identifier),
3426}
3427
3428/// Represent a LIMIT clause that restricts the number of returned rows.
3429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3430#[cfg_attr(feature = "bindings", derive(TS))]
3431pub struct Limit {
3432    /// The limit count expression.
3433    pub this: Expression,
3434    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3435    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3436    pub percent: bool,
3437    /// Comments from before the LIMIT keyword (emitted after the limit value)
3438    #[serde(default)]
3439    #[serde(skip_serializing_if = "Vec::is_empty")]
3440    pub comments: Vec<String>,
3441}
3442
3443/// OFFSET clause
3444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3445#[cfg_attr(feature = "bindings", derive(TS))]
3446pub struct Offset {
3447    pub this: Expression,
3448    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3449    #[serde(skip_serializing_if = "Option::is_none", default)]
3450    pub rows: Option<bool>,
3451}
3452
3453/// TOP clause (SQL Server)
3454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3455#[cfg_attr(feature = "bindings", derive(TS))]
3456pub struct Top {
3457    pub this: Expression,
3458    pub percent: bool,
3459    pub with_ties: bool,
3460    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3461    #[serde(default)]
3462    pub parenthesized: bool,
3463}
3464
3465/// FETCH FIRST/NEXT clause (SQL standard)
3466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3467#[cfg_attr(feature = "bindings", derive(TS))]
3468pub struct Fetch {
3469    /// FIRST or NEXT
3470    pub direction: String,
3471    /// Count expression (optional)
3472    pub count: Option<Expression>,
3473    /// PERCENT modifier
3474    pub percent: bool,
3475    /// ROWS or ROW keyword present
3476    pub rows: bool,
3477    /// WITH TIES modifier
3478    pub with_ties: bool,
3479}
3480
3481/// Represent a QUALIFY clause for filtering on window function results.
3482///
3483/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3484/// typically references a window function (e.g.
3485/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3487#[cfg_attr(feature = "bindings", derive(TS))]
3488pub struct Qualify {
3489    /// The filter predicate over window function results.
3490    pub this: Expression,
3491}
3492
3493/// SAMPLE / TABLESAMPLE clause
3494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3495#[cfg_attr(feature = "bindings", derive(TS))]
3496pub struct Sample {
3497    pub method: SampleMethod,
3498    pub size: Expression,
3499    pub seed: Option<Expression>,
3500    /// ClickHouse OFFSET expression after SAMPLE size
3501    #[serde(default)]
3502    pub offset: Option<Expression>,
3503    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
3504    pub unit_after_size: bool,
3505    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
3506    #[serde(default)]
3507    pub use_sample_keyword: bool,
3508    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
3509    #[serde(default)]
3510    pub explicit_method: bool,
3511    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
3512    #[serde(default)]
3513    pub method_before_size: bool,
3514    /// Whether SEED keyword was used (true) or REPEATABLE (false)
3515    #[serde(default)]
3516    pub use_seed_keyword: bool,
3517    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
3518    pub bucket_numerator: Option<Box<Expression>>,
3519    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
3520    pub bucket_denominator: Option<Box<Expression>>,
3521    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
3522    pub bucket_field: Option<Box<Expression>>,
3523    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
3524    #[serde(default)]
3525    pub is_using_sample: bool,
3526    /// Whether the unit was explicitly PERCENT (vs ROWS)
3527    #[serde(default)]
3528    pub is_percent: bool,
3529    /// Whether to suppress method output (for cross-dialect transpilation)
3530    #[serde(default)]
3531    pub suppress_method_output: bool,
3532}
3533
3534/// Sample method
3535#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3536#[cfg_attr(feature = "bindings", derive(TS))]
3537pub enum SampleMethod {
3538    Bernoulli,
3539    System,
3540    Block,
3541    Row,
3542    Percent,
3543    /// Hive bucket sampling
3544    Bucket,
3545    /// DuckDB reservoir sampling
3546    Reservoir,
3547}
3548
3549/// Named window definition (WINDOW w AS (...))
3550#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3551#[cfg_attr(feature = "bindings", derive(TS))]
3552pub struct NamedWindow {
3553    pub name: Identifier,
3554    pub spec: Over,
3555}
3556
3557/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
3558///
3559/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
3560/// that reference themselves. Each CTE is defined in the `ctes` vector and
3561/// can be referenced by name in subsequent CTEs and in the main query body.
3562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3563#[cfg_attr(feature = "bindings", derive(TS))]
3564pub struct With {
3565    /// The list of CTE definitions, in order.
3566    pub ctes: Vec<Cte>,
3567    /// Whether the WITH RECURSIVE keyword was used.
3568    pub recursive: bool,
3569    /// Leading comments before the statement
3570    #[serde(default)]
3571    pub leading_comments: Vec<String>,
3572    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
3573    #[serde(default, skip_serializing_if = "Option::is_none")]
3574    pub search: Option<Box<Expression>>,
3575}
3576
3577/// Represent a single Common Table Expression definition.
3578///
3579/// A CTE has a name (`alias`), an optional column list, and a body query.
3580/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
3581/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
3582/// the expression comes before the alias (`alias_first`).
3583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3584#[cfg_attr(feature = "bindings", derive(TS))]
3585pub struct Cte {
3586    /// The CTE name.
3587    pub alias: Identifier,
3588    /// The CTE body (typically a SELECT, UNION, etc.).
3589    pub this: Expression,
3590    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
3591    pub columns: Vec<Identifier>,
3592    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
3593    pub materialized: Option<bool>,
3594    /// USING KEY (columns) for DuckDB recursive CTEs
3595    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3596    pub key_expressions: Vec<Identifier>,
3597    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
3598    #[serde(default)]
3599    pub alias_first: bool,
3600    /// Comments associated with this CTE (placed after alias name, before AS)
3601    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3602    pub comments: Vec<String>,
3603}
3604
3605/// Window specification
3606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3607#[cfg_attr(feature = "bindings", derive(TS))]
3608pub struct WindowSpec {
3609    pub partition_by: Vec<Expression>,
3610    pub order_by: Vec<Ordered>,
3611    pub frame: Option<WindowFrame>,
3612}
3613
3614/// OVER clause
3615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3616#[cfg_attr(feature = "bindings", derive(TS))]
3617pub struct Over {
3618    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
3619    pub window_name: Option<Identifier>,
3620    pub partition_by: Vec<Expression>,
3621    pub order_by: Vec<Ordered>,
3622    pub frame: Option<WindowFrame>,
3623    pub alias: Option<Identifier>,
3624}
3625
3626/// Window frame
3627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3628#[cfg_attr(feature = "bindings", derive(TS))]
3629pub struct WindowFrame {
3630    pub kind: WindowFrameKind,
3631    pub start: WindowFrameBound,
3632    pub end: Option<WindowFrameBound>,
3633    pub exclude: Option<WindowFrameExclude>,
3634    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
3635    #[serde(default, skip_serializing_if = "Option::is_none")]
3636    pub kind_text: Option<String>,
3637    /// Original text of the start bound side keyword (e.g. "preceding")
3638    #[serde(default, skip_serializing_if = "Option::is_none")]
3639    pub start_side_text: Option<String>,
3640    /// Original text of the end bound side keyword
3641    #[serde(default, skip_serializing_if = "Option::is_none")]
3642    pub end_side_text: Option<String>,
3643}
3644
3645#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3646#[cfg_attr(feature = "bindings", derive(TS))]
3647pub enum WindowFrameKind {
3648    Rows,
3649    Range,
3650    Groups,
3651}
3652
3653/// EXCLUDE clause for window frames
3654#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3655#[cfg_attr(feature = "bindings", derive(TS))]
3656pub enum WindowFrameExclude {
3657    CurrentRow,
3658    Group,
3659    Ties,
3660    NoOthers,
3661}
3662
3663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3664#[cfg_attr(feature = "bindings", derive(TS))]
3665pub enum WindowFrameBound {
3666    CurrentRow,
3667    UnboundedPreceding,
3668    UnboundedFollowing,
3669    Preceding(Box<Expression>),
3670    Following(Box<Expression>),
3671    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
3672    BarePreceding,
3673    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
3674    BareFollowing,
3675    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
3676    Value(Box<Expression>),
3677}
3678
3679/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
3680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3681#[cfg_attr(feature = "bindings", derive(TS))]
3682pub struct StructField {
3683    pub name: String,
3684    pub data_type: DataType,
3685    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3686    pub options: Vec<Expression>,
3687    #[serde(default, skip_serializing_if = "Option::is_none")]
3688    pub comment: Option<String>,
3689}
3690
3691impl StructField {
3692    /// Create a new struct field without options
3693    pub fn new(name: String, data_type: DataType) -> Self {
3694        Self {
3695            name,
3696            data_type,
3697            options: Vec::new(),
3698            comment: None,
3699        }
3700    }
3701
3702    /// Create a new struct field with options
3703    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
3704        Self {
3705            name,
3706            data_type,
3707            options,
3708            comment: None,
3709        }
3710    }
3711
3712    /// Create a new struct field with options and comment
3713    pub fn with_options_and_comment(
3714        name: String,
3715        data_type: DataType,
3716        options: Vec<Expression>,
3717        comment: Option<String>,
3718    ) -> Self {
3719        Self {
3720            name,
3721            data_type,
3722            options,
3723            comment,
3724        }
3725    }
3726}
3727
3728/// Enumerate all SQL data types recognized by the parser.
3729///
3730/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
3731/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
3732/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
3733///
3734/// This enum is used in CAST expressions, column definitions, function return
3735/// types, and anywhere a data type specification appears in SQL.
3736///
3737/// Types that do not match any known variant fall through to `Custom { name }`,
3738/// preserving the original type name for round-trip fidelity.
3739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3740#[cfg_attr(feature = "bindings", derive(TS))]
3741#[serde(tag = "data_type", rename_all = "snake_case")]
3742pub enum DataType {
3743    // Numeric
3744    Boolean,
3745    TinyInt {
3746        length: Option<u32>,
3747    },
3748    SmallInt {
3749        length: Option<u32>,
3750    },
3751    /// Int type with optional length. `integer_spelling` indicates whether the original
3752    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
3753    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
3754    Int {
3755        length: Option<u32>,
3756        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3757        integer_spelling: bool,
3758    },
3759    BigInt {
3760        length: Option<u32>,
3761    },
3762    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
3763    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
3764    /// preserve the original spelling.
3765    Float {
3766        precision: Option<u32>,
3767        scale: Option<u32>,
3768        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3769        real_spelling: bool,
3770    },
3771    Double {
3772        precision: Option<u32>,
3773        scale: Option<u32>,
3774    },
3775    Decimal {
3776        precision: Option<u32>,
3777        scale: Option<u32>,
3778    },
3779
3780    // String
3781    Char {
3782        length: Option<u32>,
3783    },
3784    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
3785    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
3786    VarChar {
3787        length: Option<u32>,
3788        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3789        parenthesized_length: bool,
3790    },
3791    /// String type with optional max length (BigQuery STRING(n))
3792    String {
3793        length: Option<u32>,
3794    },
3795    Text,
3796    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
3797    TextWithLength {
3798        length: u32,
3799    },
3800
3801    // Binary
3802    Binary {
3803        length: Option<u32>,
3804    },
3805    VarBinary {
3806        length: Option<u32>,
3807    },
3808    Blob,
3809
3810    // Bit
3811    Bit {
3812        length: Option<u32>,
3813    },
3814    VarBit {
3815        length: Option<u32>,
3816    },
3817
3818    // Date/Time
3819    Date,
3820    Time {
3821        precision: Option<u32>,
3822        #[serde(default)]
3823        timezone: bool,
3824    },
3825    Timestamp {
3826        precision: Option<u32>,
3827        timezone: bool,
3828    },
3829    Interval {
3830        unit: Option<String>,
3831        /// For range intervals like INTERVAL DAY TO HOUR
3832        #[serde(default, skip_serializing_if = "Option::is_none")]
3833        to: Option<String>,
3834    },
3835
3836    // JSON
3837    Json,
3838    JsonB,
3839
3840    // UUID
3841    Uuid,
3842
3843    // Array
3844    Array {
3845        element_type: Box<DataType>,
3846        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
3847        #[serde(default, skip_serializing_if = "Option::is_none")]
3848        dimension: Option<u32>,
3849    },
3850
3851    /// List type (Materialize): INT LIST, TEXT LIST LIST
3852    /// Uses postfix LIST syntax instead of ARRAY<T>
3853    List {
3854        element_type: Box<DataType>,
3855    },
3856
3857    // Struct/Map
3858    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
3859    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
3860    Struct {
3861        fields: Vec<StructField>,
3862        nested: bool,
3863    },
3864    Map {
3865        key_type: Box<DataType>,
3866        value_type: Box<DataType>,
3867    },
3868
3869    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
3870    Enum {
3871        values: Vec<String>,
3872        #[serde(default, skip_serializing_if = "Vec::is_empty")]
3873        assignments: Vec<Option<String>>,
3874    },
3875
3876    // Set type (MySQL): SET('a', 'b', 'c')
3877    Set {
3878        values: Vec<String>,
3879    },
3880
3881    // Union type (DuckDB): UNION(num INT, str TEXT)
3882    Union {
3883        fields: Vec<(String, DataType)>,
3884    },
3885
3886    // Vector (Snowflake / SingleStore)
3887    Vector {
3888        #[serde(default)]
3889        element_type: Option<Box<DataType>>,
3890        dimension: Option<u32>,
3891    },
3892
3893    // Object (Snowflake structured type)
3894    // fields: Vec of (field_name, field_type, not_null)
3895    Object {
3896        fields: Vec<(String, DataType, bool)>,
3897        modifier: Option<String>,
3898    },
3899
3900    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
3901    Nullable {
3902        inner: Box<DataType>,
3903    },
3904
3905    // Custom/User-defined
3906    Custom {
3907        name: String,
3908    },
3909
3910    // Spatial types
3911    Geometry {
3912        subtype: Option<String>,
3913        srid: Option<u32>,
3914    },
3915    Geography {
3916        subtype: Option<String>,
3917        srid: Option<u32>,
3918    },
3919
3920    // Character Set (for CONVERT USING in MySQL)
3921    // Renders as CHAR CHARACTER SET {name} in cast target
3922    CharacterSet {
3923        name: String,
3924    },
3925
3926    // Unknown
3927    Unknown,
3928}
3929
3930/// Array expression
3931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3932#[cfg_attr(feature = "bindings", derive(TS))]
3933#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
3934pub struct Array {
3935    pub expressions: Vec<Expression>,
3936}
3937
3938/// Struct expression
3939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3940#[cfg_attr(feature = "bindings", derive(TS))]
3941pub struct Struct {
3942    pub fields: Vec<(Option<String>, Expression)>,
3943}
3944
3945/// Tuple expression
3946#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3947#[cfg_attr(feature = "bindings", derive(TS))]
3948pub struct Tuple {
3949    pub expressions: Vec<Expression>,
3950}
3951
3952/// Interval expression
3953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3954#[cfg_attr(feature = "bindings", derive(TS))]
3955pub struct Interval {
3956    /// The value expression (e.g., '1', 5, column_ref)
3957    pub this: Option<Expression>,
3958    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
3959    pub unit: Option<IntervalUnitSpec>,
3960}
3961
3962/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
3963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3964#[cfg_attr(feature = "bindings", derive(TS))]
3965#[serde(tag = "type", rename_all = "snake_case")]
3966pub enum IntervalUnitSpec {
3967    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
3968    Simple {
3969        unit: IntervalUnit,
3970        /// Whether to use plural form (e.g., DAYS vs DAY)
3971        use_plural: bool,
3972    },
3973    /// Interval span (e.g., HOUR TO SECOND)
3974    Span(IntervalSpan),
3975    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3976    /// The start and end can be expressions like function calls with precision
3977    ExprSpan(IntervalSpanExpr),
3978    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
3979    Expr(Box<Expression>),
3980}
3981
3982/// Interval span for ranges like HOUR TO SECOND
3983#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3984#[cfg_attr(feature = "bindings", derive(TS))]
3985pub struct IntervalSpan {
3986    /// Start unit (e.g., HOUR)
3987    pub this: IntervalUnit,
3988    /// End unit (e.g., SECOND)
3989    pub expression: IntervalUnit,
3990}
3991
3992/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3993/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
3994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3995#[cfg_attr(feature = "bindings", derive(TS))]
3996pub struct IntervalSpanExpr {
3997    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
3998    pub this: Box<Expression>,
3999    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
4000    pub expression: Box<Expression>,
4001}
4002
4003#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4004#[cfg_attr(feature = "bindings", derive(TS))]
4005pub enum IntervalUnit {
4006    Year,
4007    Quarter,
4008    Month,
4009    Week,
4010    Day,
4011    Hour,
4012    Minute,
4013    Second,
4014    Millisecond,
4015    Microsecond,
4016    Nanosecond,
4017}
4018
4019/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
4020#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4021#[cfg_attr(feature = "bindings", derive(TS))]
4022pub struct Command {
4023    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
4024    pub this: String,
4025}
4026
4027/// EXEC/EXECUTE statement (TSQL stored procedure call)
4028/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
4029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4030#[cfg_attr(feature = "bindings", derive(TS))]
4031pub struct ExecuteStatement {
4032    /// The procedure name (can be qualified: schema.proc_name)
4033    pub this: Expression,
4034    /// Named parameters: @param=value pairs
4035    #[serde(default)]
4036    pub parameters: Vec<ExecuteParameter>,
4037}
4038
4039/// Named parameter in EXEC statement: @name=value
4040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4041#[cfg_attr(feature = "bindings", derive(TS))]
4042pub struct ExecuteParameter {
4043    /// Parameter name (including @)
4044    pub name: String,
4045    /// Parameter value
4046    pub value: Expression,
4047}
4048
4049/// KILL statement (MySQL/MariaDB)
4050/// KILL [CONNECTION | QUERY] <id>
4051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4052#[cfg_attr(feature = "bindings", derive(TS))]
4053pub struct Kill {
4054    /// The target (process ID or connection ID)
4055    pub this: Expression,
4056    /// Optional kind: "CONNECTION" or "QUERY"
4057    pub kind: Option<String>,
4058}
4059
4060/// Raw/unparsed SQL
4061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4062#[cfg_attr(feature = "bindings", derive(TS))]
4063pub struct Raw {
4064    pub sql: String,
4065}
4066
4067// ============================================================================
4068// Function expression types
4069// ============================================================================
4070
4071/// Generic unary function (takes a single argument)
4072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4073#[cfg_attr(feature = "bindings", derive(TS))]
4074pub struct UnaryFunc {
4075    pub this: Expression,
4076    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4077    #[serde(skip_serializing_if = "Option::is_none", default)]
4078    pub original_name: Option<String>,
4079}
4080
4081impl UnaryFunc {
4082    /// Create a new UnaryFunc with no original_name
4083    pub fn new(this: Expression) -> Self {
4084        Self {
4085            this,
4086            original_name: None,
4087        }
4088    }
4089
4090    /// Create a new UnaryFunc with an original name for round-trip preservation
4091    pub fn with_name(this: Expression, name: String) -> Self {
4092        Self {
4093            this,
4094            original_name: Some(name),
4095        }
4096    }
4097}
4098
4099/// CHAR/CHR function with multiple args and optional USING charset
4100/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4101/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4103#[cfg_attr(feature = "bindings", derive(TS))]
4104pub struct CharFunc {
4105    pub args: Vec<Expression>,
4106    #[serde(skip_serializing_if = "Option::is_none", default)]
4107    pub charset: Option<String>,
4108    /// Original function name (CHAR or CHR), defaults to CHAR
4109    #[serde(skip_serializing_if = "Option::is_none", default)]
4110    pub name: Option<String>,
4111}
4112
4113/// Generic binary function (takes two arguments)
4114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4115#[cfg_attr(feature = "bindings", derive(TS))]
4116pub struct BinaryFunc {
4117    pub this: Expression,
4118    pub expression: Expression,
4119    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4120    #[serde(skip_serializing_if = "Option::is_none", default)]
4121    pub original_name: Option<String>,
4122}
4123
4124/// Variable argument function
4125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4126#[cfg_attr(feature = "bindings", derive(TS))]
4127pub struct VarArgFunc {
4128    pub expressions: Vec<Expression>,
4129    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4130    #[serde(skip_serializing_if = "Option::is_none", default)]
4131    pub original_name: Option<String>,
4132}
4133
4134/// CONCAT_WS function
4135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4136#[cfg_attr(feature = "bindings", derive(TS))]
4137pub struct ConcatWs {
4138    pub separator: Expression,
4139    pub expressions: Vec<Expression>,
4140}
4141
4142/// SUBSTRING function
4143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4144#[cfg_attr(feature = "bindings", derive(TS))]
4145pub struct SubstringFunc {
4146    pub this: Expression,
4147    pub start: Expression,
4148    pub length: Option<Expression>,
4149    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4150    #[serde(default)]
4151    pub from_for_syntax: bool,
4152}
4153
4154/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4156#[cfg_attr(feature = "bindings", derive(TS))]
4157pub struct OverlayFunc {
4158    pub this: Expression,
4159    pub replacement: Expression,
4160    pub from: Expression,
4161    pub length: Option<Expression>,
4162}
4163
4164/// TRIM function
4165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4166#[cfg_attr(feature = "bindings", derive(TS))]
4167pub struct TrimFunc {
4168    pub this: Expression,
4169    pub characters: Option<Expression>,
4170    pub position: TrimPosition,
4171    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4172    #[serde(default)]
4173    pub sql_standard_syntax: bool,
4174    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4175    #[serde(default)]
4176    pub position_explicit: bool,
4177}
4178
4179#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4180#[cfg_attr(feature = "bindings", derive(TS))]
4181pub enum TrimPosition {
4182    Both,
4183    Leading,
4184    Trailing,
4185}
4186
4187/// REPLACE function
4188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4189#[cfg_attr(feature = "bindings", derive(TS))]
4190pub struct ReplaceFunc {
4191    pub this: Expression,
4192    pub old: Expression,
4193    pub new: Expression,
4194}
4195
4196/// LEFT/RIGHT function
4197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4198#[cfg_attr(feature = "bindings", derive(TS))]
4199pub struct LeftRightFunc {
4200    pub this: Expression,
4201    pub length: Expression,
4202}
4203
4204/// REPEAT function
4205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4206#[cfg_attr(feature = "bindings", derive(TS))]
4207pub struct RepeatFunc {
4208    pub this: Expression,
4209    pub times: Expression,
4210}
4211
4212/// LPAD/RPAD function
4213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4214#[cfg_attr(feature = "bindings", derive(TS))]
4215pub struct PadFunc {
4216    pub this: Expression,
4217    pub length: Expression,
4218    pub fill: Option<Expression>,
4219}
4220
4221/// SPLIT function
4222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4223#[cfg_attr(feature = "bindings", derive(TS))]
4224pub struct SplitFunc {
4225    pub this: Expression,
4226    pub delimiter: Expression,
4227}
4228
4229/// REGEXP_LIKE function
4230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4231#[cfg_attr(feature = "bindings", derive(TS))]
4232pub struct RegexpFunc {
4233    pub this: Expression,
4234    pub pattern: Expression,
4235    pub flags: Option<Expression>,
4236}
4237
4238/// REGEXP_REPLACE function
4239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4240#[cfg_attr(feature = "bindings", derive(TS))]
4241pub struct RegexpReplaceFunc {
4242    pub this: Expression,
4243    pub pattern: Expression,
4244    pub replacement: Expression,
4245    pub flags: Option<Expression>,
4246}
4247
4248/// REGEXP_EXTRACT function
4249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4250#[cfg_attr(feature = "bindings", derive(TS))]
4251pub struct RegexpExtractFunc {
4252    pub this: Expression,
4253    pub pattern: Expression,
4254    pub group: Option<Expression>,
4255}
4256
4257/// ROUND function
4258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4259#[cfg_attr(feature = "bindings", derive(TS))]
4260pub struct RoundFunc {
4261    pub this: Expression,
4262    pub decimals: Option<Expression>,
4263}
4264
4265/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4267#[cfg_attr(feature = "bindings", derive(TS))]
4268pub struct FloorFunc {
4269    pub this: Expression,
4270    pub scale: Option<Expression>,
4271    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4272    #[serde(skip_serializing_if = "Option::is_none", default)]
4273    pub to: Option<Expression>,
4274}
4275
4276/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4278#[cfg_attr(feature = "bindings", derive(TS))]
4279pub struct CeilFunc {
4280    pub this: Expression,
4281    #[serde(skip_serializing_if = "Option::is_none", default)]
4282    pub decimals: Option<Expression>,
4283    /// Time unit for Druid-style CEIL(time TO unit) syntax
4284    #[serde(skip_serializing_if = "Option::is_none", default)]
4285    pub to: Option<Expression>,
4286}
4287
4288/// LOG function
4289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4290#[cfg_attr(feature = "bindings", derive(TS))]
4291pub struct LogFunc {
4292    pub this: Expression,
4293    pub base: Option<Expression>,
4294}
4295
4296/// CURRENT_DATE (no arguments)
4297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4298#[cfg_attr(feature = "bindings", derive(TS))]
4299pub struct CurrentDate;
4300
4301/// CURRENT_TIME
4302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4303#[cfg_attr(feature = "bindings", derive(TS))]
4304pub struct CurrentTime {
4305    pub precision: Option<u32>,
4306}
4307
4308/// CURRENT_TIMESTAMP
4309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4310#[cfg_attr(feature = "bindings", derive(TS))]
4311pub struct CurrentTimestamp {
4312    pub precision: Option<u32>,
4313    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4314    #[serde(default)]
4315    pub sysdate: bool,
4316}
4317
4318/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4320#[cfg_attr(feature = "bindings", derive(TS))]
4321pub struct CurrentTimestampLTZ {
4322    pub precision: Option<u32>,
4323}
4324
4325/// AT TIME ZONE expression for timezone conversion
4326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4327#[cfg_attr(feature = "bindings", derive(TS))]
4328pub struct AtTimeZone {
4329    /// The expression to convert
4330    pub this: Expression,
4331    /// The target timezone
4332    pub zone: Expression,
4333}
4334
4335/// DATE_ADD / DATE_SUB function
4336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4337#[cfg_attr(feature = "bindings", derive(TS))]
4338pub struct DateAddFunc {
4339    pub this: Expression,
4340    pub interval: Expression,
4341    pub unit: IntervalUnit,
4342}
4343
4344/// DATEDIFF function
4345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4346#[cfg_attr(feature = "bindings", derive(TS))]
4347pub struct DateDiffFunc {
4348    pub this: Expression,
4349    pub expression: Expression,
4350    pub unit: Option<IntervalUnit>,
4351}
4352
4353/// DATE_TRUNC function
4354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4355#[cfg_attr(feature = "bindings", derive(TS))]
4356pub struct DateTruncFunc {
4357    pub this: Expression,
4358    pub unit: DateTimeField,
4359}
4360
4361/// EXTRACT function
4362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4363#[cfg_attr(feature = "bindings", derive(TS))]
4364pub struct ExtractFunc {
4365    pub this: Expression,
4366    pub field: DateTimeField,
4367}
4368
4369#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4370#[cfg_attr(feature = "bindings", derive(TS))]
4371pub enum DateTimeField {
4372    Year,
4373    Month,
4374    Day,
4375    Hour,
4376    Minute,
4377    Second,
4378    Millisecond,
4379    Microsecond,
4380    DayOfWeek,
4381    DayOfYear,
4382    Week,
4383    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4384    WeekWithModifier(String),
4385    Quarter,
4386    Epoch,
4387    Timezone,
4388    TimezoneHour,
4389    TimezoneMinute,
4390    Date,
4391    Time,
4392    /// Custom datetime field for dialect-specific or arbitrary fields
4393    Custom(String),
4394}
4395
4396/// TO_DATE function
4397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4398#[cfg_attr(feature = "bindings", derive(TS))]
4399pub struct ToDateFunc {
4400    pub this: Expression,
4401    pub format: Option<Expression>,
4402}
4403
4404/// TO_TIMESTAMP function
4405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4406#[cfg_attr(feature = "bindings", derive(TS))]
4407pub struct ToTimestampFunc {
4408    pub this: Expression,
4409    pub format: Option<Expression>,
4410}
4411
4412/// IF function
4413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4414#[cfg_attr(feature = "bindings", derive(TS))]
4415pub struct IfFunc {
4416    pub condition: Expression,
4417    pub true_value: Expression,
4418    pub false_value: Option<Expression>,
4419    /// Original function name (IF, IFF, IIF) for round-trip preservation
4420    #[serde(skip_serializing_if = "Option::is_none", default)]
4421    pub original_name: Option<String>,
4422}
4423
4424/// NVL2 function
4425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4426#[cfg_attr(feature = "bindings", derive(TS))]
4427pub struct Nvl2Func {
4428    pub this: Expression,
4429    pub true_value: Expression,
4430    pub false_value: Expression,
4431}
4432
4433// ============================================================================
4434// Typed Aggregate Function types
4435// ============================================================================
4436
4437/// Generic aggregate function base type
4438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4439#[cfg_attr(feature = "bindings", derive(TS))]
4440pub struct AggFunc {
4441    pub this: Expression,
4442    pub distinct: bool,
4443    pub filter: Option<Expression>,
4444    pub order_by: Vec<Ordered>,
4445    /// Original function name (case-preserving) when parsed from SQL
4446    #[serde(skip_serializing_if = "Option::is_none", default)]
4447    pub name: Option<String>,
4448    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4449    #[serde(skip_serializing_if = "Option::is_none", default)]
4450    pub ignore_nulls: Option<bool>,
4451    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4452    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4453    #[serde(skip_serializing_if = "Option::is_none", default)]
4454    pub having_max: Option<(Box<Expression>, bool)>,
4455    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4456    #[serde(skip_serializing_if = "Option::is_none", default)]
4457    pub limit: Option<Box<Expression>>,
4458}
4459
4460/// COUNT function with optional star
4461#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4462#[cfg_attr(feature = "bindings", derive(TS))]
4463pub struct CountFunc {
4464    pub this: Option<Expression>,
4465    pub star: bool,
4466    pub distinct: bool,
4467    pub filter: Option<Expression>,
4468    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4469    #[serde(default, skip_serializing_if = "Option::is_none")]
4470    pub ignore_nulls: Option<bool>,
4471    /// Original function name for case preservation (e.g., "count" or "COUNT")
4472    #[serde(default, skip_serializing_if = "Option::is_none")]
4473    pub original_name: Option<String>,
4474}
4475
4476/// GROUP_CONCAT function (MySQL style)
4477#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4478#[cfg_attr(feature = "bindings", derive(TS))]
4479pub struct GroupConcatFunc {
4480    pub this: Expression,
4481    pub separator: Option<Expression>,
4482    pub order_by: Option<Vec<Ordered>>,
4483    pub distinct: bool,
4484    pub filter: Option<Expression>,
4485}
4486
4487/// STRING_AGG function (PostgreSQL/Standard SQL)
4488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4489#[cfg_attr(feature = "bindings", derive(TS))]
4490pub struct StringAggFunc {
4491    pub this: Expression,
4492    #[serde(default)]
4493    pub separator: Option<Expression>,
4494    #[serde(default)]
4495    pub order_by: Option<Vec<Ordered>>,
4496    #[serde(default)]
4497    pub distinct: bool,
4498    #[serde(default)]
4499    pub filter: Option<Expression>,
4500    /// BigQuery LIMIT inside STRING_AGG
4501    #[serde(default, skip_serializing_if = "Option::is_none")]
4502    pub limit: Option<Box<Expression>>,
4503}
4504
4505/// LISTAGG function (Oracle style)
4506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4507#[cfg_attr(feature = "bindings", derive(TS))]
4508pub struct ListAggFunc {
4509    pub this: Expression,
4510    pub separator: Option<Expression>,
4511    pub on_overflow: Option<ListAggOverflow>,
4512    pub order_by: Option<Vec<Ordered>>,
4513    pub distinct: bool,
4514    pub filter: Option<Expression>,
4515}
4516
4517/// LISTAGG ON OVERFLOW behavior
4518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4519#[cfg_attr(feature = "bindings", derive(TS))]
4520pub enum ListAggOverflow {
4521    Error,
4522    Truncate {
4523        filler: Option<Expression>,
4524        with_count: bool,
4525    },
4526}
4527
4528/// SUM_IF / COUNT_IF function
4529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4530#[cfg_attr(feature = "bindings", derive(TS))]
4531pub struct SumIfFunc {
4532    pub this: Expression,
4533    pub condition: Expression,
4534    pub filter: Option<Expression>,
4535}
4536
4537/// APPROX_PERCENTILE function
4538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4539#[cfg_attr(feature = "bindings", derive(TS))]
4540pub struct ApproxPercentileFunc {
4541    pub this: Expression,
4542    pub percentile: Expression,
4543    pub accuracy: Option<Expression>,
4544    pub filter: Option<Expression>,
4545}
4546
4547/// PERCENTILE_CONT / PERCENTILE_DISC function
4548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4549#[cfg_attr(feature = "bindings", derive(TS))]
4550pub struct PercentileFunc {
4551    pub this: Expression,
4552    pub percentile: Expression,
4553    pub order_by: Option<Vec<Ordered>>,
4554    pub filter: Option<Expression>,
4555}
4556
4557// ============================================================================
4558// Typed Window Function types
4559// ============================================================================
4560
4561/// ROW_NUMBER function (no arguments)
4562#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4563#[cfg_attr(feature = "bindings", derive(TS))]
4564pub struct RowNumber;
4565
4566/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4568#[cfg_attr(feature = "bindings", derive(TS))]
4569pub struct Rank {
4570    /// DuckDB: RANK(ORDER BY col) - order by inside function
4571    #[serde(default, skip_serializing_if = "Option::is_none")]
4572    pub order_by: Option<Vec<Ordered>>,
4573    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4574    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4575    pub args: Vec<Expression>,
4576}
4577
4578/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
4579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4580#[cfg_attr(feature = "bindings", derive(TS))]
4581pub struct DenseRank {
4582    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4583    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4584    pub args: Vec<Expression>,
4585}
4586
4587/// NTILE function (DuckDB allows ORDER BY inside)
4588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4589#[cfg_attr(feature = "bindings", derive(TS))]
4590pub struct NTileFunc {
4591    /// num_buckets is optional to support Databricks NTILE() without arguments
4592    #[serde(default, skip_serializing_if = "Option::is_none")]
4593    pub num_buckets: Option<Expression>,
4594    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
4595    #[serde(default, skip_serializing_if = "Option::is_none")]
4596    pub order_by: Option<Vec<Ordered>>,
4597}
4598
4599/// LEAD / LAG function
4600#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4601#[cfg_attr(feature = "bindings", derive(TS))]
4602pub struct LeadLagFunc {
4603    pub this: Expression,
4604    pub offset: Option<Expression>,
4605    pub default: Option<Expression>,
4606    pub ignore_nulls: bool,
4607}
4608
4609/// FIRST_VALUE / LAST_VALUE function
4610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4611#[cfg_attr(feature = "bindings", derive(TS))]
4612pub struct ValueFunc {
4613    pub this: Expression,
4614    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4615    #[serde(default, skip_serializing_if = "Option::is_none")]
4616    pub ignore_nulls: Option<bool>,
4617}
4618
4619/// NTH_VALUE function
4620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4621#[cfg_attr(feature = "bindings", derive(TS))]
4622pub struct NthValueFunc {
4623    pub this: Expression,
4624    pub offset: Expression,
4625    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4626    #[serde(default, skip_serializing_if = "Option::is_none")]
4627    pub ignore_nulls: Option<bool>,
4628    /// Snowflake FROM FIRST / FROM LAST clause
4629    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
4630    #[serde(default, skip_serializing_if = "Option::is_none")]
4631    pub from_first: Option<bool>,
4632}
4633
4634/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4636#[cfg_attr(feature = "bindings", derive(TS))]
4637pub struct PercentRank {
4638    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
4639    #[serde(default, skip_serializing_if = "Option::is_none")]
4640    pub order_by: Option<Vec<Ordered>>,
4641    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4642    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4643    pub args: Vec<Expression>,
4644}
4645
4646/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4648#[cfg_attr(feature = "bindings", derive(TS))]
4649pub struct CumeDist {
4650    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
4651    #[serde(default, skip_serializing_if = "Option::is_none")]
4652    pub order_by: Option<Vec<Ordered>>,
4653    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4654    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4655    pub args: Vec<Expression>,
4656}
4657
4658// ============================================================================
4659// Additional String Function types
4660// ============================================================================
4661
4662/// POSITION/INSTR function
4663#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4664#[cfg_attr(feature = "bindings", derive(TS))]
4665pub struct PositionFunc {
4666    pub substring: Expression,
4667    pub string: Expression,
4668    pub start: Option<Expression>,
4669}
4670
4671// ============================================================================
4672// Additional Math Function types
4673// ============================================================================
4674
4675/// RANDOM function (no arguments)
4676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4677#[cfg_attr(feature = "bindings", derive(TS))]
4678pub struct Random;
4679
4680/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
4681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4682#[cfg_attr(feature = "bindings", derive(TS))]
4683pub struct Rand {
4684    pub seed: Option<Box<Expression>>,
4685    /// Teradata RANDOM lower bound
4686    #[serde(default)]
4687    pub lower: Option<Box<Expression>>,
4688    /// Teradata RANDOM upper bound
4689    #[serde(default)]
4690    pub upper: Option<Box<Expression>>,
4691}
4692
4693/// TRUNCATE / TRUNC function
4694#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4695#[cfg_attr(feature = "bindings", derive(TS))]
4696pub struct TruncateFunc {
4697    pub this: Expression,
4698    pub decimals: Option<Expression>,
4699}
4700
4701/// PI function (no arguments)
4702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4703#[cfg_attr(feature = "bindings", derive(TS))]
4704pub struct Pi;
4705
4706// ============================================================================
4707// Control Flow Function types
4708// ============================================================================
4709
4710/// DECODE function (Oracle style)
4711#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4712#[cfg_attr(feature = "bindings", derive(TS))]
4713pub struct DecodeFunc {
4714    pub this: Expression,
4715    pub search_results: Vec<(Expression, Expression)>,
4716    pub default: Option<Expression>,
4717}
4718
4719// ============================================================================
4720// Additional Date/Time Function types
4721// ============================================================================
4722
4723/// DATE_FORMAT / FORMAT_DATE function
4724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4725#[cfg_attr(feature = "bindings", derive(TS))]
4726pub struct DateFormatFunc {
4727    pub this: Expression,
4728    pub format: Expression,
4729}
4730
4731/// FROM_UNIXTIME function
4732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4733#[cfg_attr(feature = "bindings", derive(TS))]
4734pub struct FromUnixtimeFunc {
4735    pub this: Expression,
4736    pub format: Option<Expression>,
4737}
4738
4739/// UNIX_TIMESTAMP function
4740#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4741#[cfg_attr(feature = "bindings", derive(TS))]
4742pub struct UnixTimestampFunc {
4743    pub this: Option<Expression>,
4744    pub format: Option<Expression>,
4745}
4746
4747/// MAKE_DATE function
4748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4749#[cfg_attr(feature = "bindings", derive(TS))]
4750pub struct MakeDateFunc {
4751    pub year: Expression,
4752    pub month: Expression,
4753    pub day: Expression,
4754}
4755
4756/// MAKE_TIMESTAMP function
4757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4758#[cfg_attr(feature = "bindings", derive(TS))]
4759pub struct MakeTimestampFunc {
4760    pub year: Expression,
4761    pub month: Expression,
4762    pub day: Expression,
4763    pub hour: Expression,
4764    pub minute: Expression,
4765    pub second: Expression,
4766    pub timezone: Option<Expression>,
4767}
4768
4769/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
4770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4771#[cfg_attr(feature = "bindings", derive(TS))]
4772pub struct LastDayFunc {
4773    pub this: Expression,
4774    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
4775    #[serde(skip_serializing_if = "Option::is_none", default)]
4776    pub unit: Option<DateTimeField>,
4777}
4778
4779// ============================================================================
4780// Array Function types
4781// ============================================================================
4782
4783/// ARRAY constructor
4784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4785#[cfg_attr(feature = "bindings", derive(TS))]
4786pub struct ArrayConstructor {
4787    pub expressions: Vec<Expression>,
4788    pub bracket_notation: bool,
4789    /// True if LIST keyword was used instead of ARRAY (DuckDB)
4790    pub use_list_keyword: bool,
4791}
4792
4793/// ARRAY_SORT function
4794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4795#[cfg_attr(feature = "bindings", derive(TS))]
4796pub struct ArraySortFunc {
4797    pub this: Expression,
4798    pub comparator: Option<Expression>,
4799    pub desc: bool,
4800    pub nulls_first: Option<bool>,
4801}
4802
4803/// ARRAY_JOIN / ARRAY_TO_STRING function
4804#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4805#[cfg_attr(feature = "bindings", derive(TS))]
4806pub struct ArrayJoinFunc {
4807    pub this: Expression,
4808    pub separator: Expression,
4809    pub null_replacement: Option<Expression>,
4810}
4811
4812/// UNNEST function
4813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4814#[cfg_attr(feature = "bindings", derive(TS))]
4815pub struct UnnestFunc {
4816    pub this: Expression,
4817    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
4818    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4819    pub expressions: Vec<Expression>,
4820    pub with_ordinality: bool,
4821    pub alias: Option<Identifier>,
4822    /// BigQuery: offset alias for WITH OFFSET AS <name>
4823    #[serde(default, skip_serializing_if = "Option::is_none")]
4824    pub offset_alias: Option<Identifier>,
4825}
4826
4827/// ARRAY_FILTER function (with lambda)
4828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4829#[cfg_attr(feature = "bindings", derive(TS))]
4830pub struct ArrayFilterFunc {
4831    pub this: Expression,
4832    pub filter: Expression,
4833}
4834
4835/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
4836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4837#[cfg_attr(feature = "bindings", derive(TS))]
4838pub struct ArrayTransformFunc {
4839    pub this: Expression,
4840    pub transform: Expression,
4841}
4842
4843/// SEQUENCE / GENERATE_SERIES function
4844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4845#[cfg_attr(feature = "bindings", derive(TS))]
4846pub struct SequenceFunc {
4847    pub start: Expression,
4848    pub stop: Expression,
4849    pub step: Option<Expression>,
4850}
4851
4852// ============================================================================
4853// Struct Function types
4854// ============================================================================
4855
4856/// STRUCT constructor
4857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4858#[cfg_attr(feature = "bindings", derive(TS))]
4859pub struct StructConstructor {
4860    pub fields: Vec<(Option<Identifier>, Expression)>,
4861}
4862
4863/// STRUCT_EXTRACT function
4864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4865#[cfg_attr(feature = "bindings", derive(TS))]
4866pub struct StructExtractFunc {
4867    pub this: Expression,
4868    pub field: Identifier,
4869}
4870
4871/// NAMED_STRUCT function
4872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4873#[cfg_attr(feature = "bindings", derive(TS))]
4874pub struct NamedStructFunc {
4875    pub pairs: Vec<(Expression, Expression)>,
4876}
4877
4878// ============================================================================
4879// Map Function types
4880// ============================================================================
4881
4882/// MAP constructor
4883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4884#[cfg_attr(feature = "bindings", derive(TS))]
4885pub struct MapConstructor {
4886    pub keys: Vec<Expression>,
4887    pub values: Vec<Expression>,
4888    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
4889    #[serde(default)]
4890    pub curly_brace_syntax: bool,
4891    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
4892    #[serde(default)]
4893    pub with_map_keyword: bool,
4894}
4895
4896/// TRANSFORM_KEYS / TRANSFORM_VALUES function
4897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4898#[cfg_attr(feature = "bindings", derive(TS))]
4899pub struct TransformFunc {
4900    pub this: Expression,
4901    pub transform: Expression,
4902}
4903
4904// ============================================================================
4905// JSON Function types
4906// ============================================================================
4907
4908/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
4909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4910#[cfg_attr(feature = "bindings", derive(TS))]
4911pub struct JsonExtractFunc {
4912    pub this: Expression,
4913    pub path: Expression,
4914    pub returning: Option<DataType>,
4915    /// True if parsed from -> or ->> operator syntax
4916    #[serde(default)]
4917    pub arrow_syntax: bool,
4918    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
4919    #[serde(default)]
4920    pub hash_arrow_syntax: bool,
4921    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
4922    #[serde(default)]
4923    pub wrapper_option: Option<String>,
4924    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
4925    #[serde(default)]
4926    pub quotes_option: Option<String>,
4927    /// ON SCALAR STRING flag
4928    #[serde(default)]
4929    pub on_scalar_string: bool,
4930    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
4931    #[serde(default)]
4932    pub on_error: Option<String>,
4933}
4934
4935/// JSON path extraction
4936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4937#[cfg_attr(feature = "bindings", derive(TS))]
4938pub struct JsonPathFunc {
4939    pub this: Expression,
4940    pub paths: Vec<Expression>,
4941}
4942
4943/// JSON_OBJECT function
4944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4945#[cfg_attr(feature = "bindings", derive(TS))]
4946pub struct JsonObjectFunc {
4947    pub pairs: Vec<(Expression, Expression)>,
4948    pub null_handling: Option<JsonNullHandling>,
4949    #[serde(default)]
4950    pub with_unique_keys: bool,
4951    #[serde(default)]
4952    pub returning_type: Option<DataType>,
4953    #[serde(default)]
4954    pub format_json: bool,
4955    #[serde(default)]
4956    pub encoding: Option<String>,
4957    /// For JSON_OBJECT(*) syntax
4958    #[serde(default)]
4959    pub star: bool,
4960}
4961
4962/// JSON null handling options
4963#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4964#[cfg_attr(feature = "bindings", derive(TS))]
4965pub enum JsonNullHandling {
4966    NullOnNull,
4967    AbsentOnNull,
4968}
4969
4970/// JSON_SET / JSON_INSERT function
4971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4972#[cfg_attr(feature = "bindings", derive(TS))]
4973pub struct JsonModifyFunc {
4974    pub this: Expression,
4975    pub path_values: Vec<(Expression, Expression)>,
4976}
4977
4978/// JSON_ARRAYAGG function
4979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4980#[cfg_attr(feature = "bindings", derive(TS))]
4981pub struct JsonArrayAggFunc {
4982    pub this: Expression,
4983    pub order_by: Option<Vec<Ordered>>,
4984    pub null_handling: Option<JsonNullHandling>,
4985    pub filter: Option<Expression>,
4986}
4987
4988/// JSON_OBJECTAGG function
4989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4990#[cfg_attr(feature = "bindings", derive(TS))]
4991pub struct JsonObjectAggFunc {
4992    pub key: Expression,
4993    pub value: Expression,
4994    pub null_handling: Option<JsonNullHandling>,
4995    pub filter: Option<Expression>,
4996}
4997
4998// ============================================================================
4999// Type Casting Function types
5000// ============================================================================
5001
5002/// CONVERT function (SQL Server style)
5003#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5004#[cfg_attr(feature = "bindings", derive(TS))]
5005pub struct ConvertFunc {
5006    pub this: Expression,
5007    pub to: DataType,
5008    pub style: Option<Expression>,
5009}
5010
5011// ============================================================================
5012// Additional Expression types
5013// ============================================================================
5014
5015/// Lambda expression
5016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5017#[cfg_attr(feature = "bindings", derive(TS))]
5018pub struct LambdaExpr {
5019    pub parameters: Vec<Identifier>,
5020    pub body: Expression,
5021    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
5022    #[serde(default)]
5023    pub colon: bool,
5024    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
5025    /// Maps parameter index to data type
5026    #[serde(default)]
5027    pub parameter_types: Vec<Option<DataType>>,
5028}
5029
5030/// Parameter (parameterized queries)
5031#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5032#[cfg_attr(feature = "bindings", derive(TS))]
5033pub struct Parameter {
5034    pub name: Option<String>,
5035    pub index: Option<u32>,
5036    pub style: ParameterStyle,
5037    /// Whether the name was quoted (e.g., @"x" vs @x)
5038    #[serde(default)]
5039    pub quoted: bool,
5040    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5041    #[serde(default)]
5042    pub string_quoted: bool,
5043    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5044    #[serde(default)]
5045    pub expression: Option<String>,
5046}
5047
5048/// Parameter placeholder styles
5049#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5050#[cfg_attr(feature = "bindings", derive(TS))]
5051pub enum ParameterStyle {
5052    Question,     // ?
5053    Dollar,       // $1, $2
5054    DollarBrace,  // ${name} (Databricks, Hive template variables)
5055    Brace,        // {name} (Spark/Databricks widget/template variables)
5056    Colon,        // :name
5057    At,           // @name
5058    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5059    DoubleDollar, // $$name
5060    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5061}
5062
5063/// Placeholder expression
5064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5065#[cfg_attr(feature = "bindings", derive(TS))]
5066pub struct Placeholder {
5067    pub index: Option<u32>,
5068}
5069
5070/// Named argument in function call: name => value or name := value
5071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5072#[cfg_attr(feature = "bindings", derive(TS))]
5073pub struct NamedArgument {
5074    pub name: Identifier,
5075    pub value: Expression,
5076    /// The separator used: `=>`, `:=`, or `=`
5077    pub separator: NamedArgSeparator,
5078}
5079
5080/// Separator style for named arguments
5081#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5082#[cfg_attr(feature = "bindings", derive(TS))]
5083pub enum NamedArgSeparator {
5084    /// `=>` (standard SQL, Snowflake, BigQuery)
5085    DArrow,
5086    /// `:=` (Oracle, MySQL)
5087    ColonEq,
5088    /// `=` (simple equals, some dialects)
5089    Eq,
5090}
5091
5092/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5093/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5094#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5095#[cfg_attr(feature = "bindings", derive(TS))]
5096pub struct TableArgument {
5097    /// The keyword prefix: "TABLE" or "MODEL"
5098    pub prefix: String,
5099    /// The table/model reference expression
5100    pub this: Expression,
5101}
5102
5103/// SQL Comment preservation
5104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5105#[cfg_attr(feature = "bindings", derive(TS))]
5106pub struct SqlComment {
5107    pub text: String,
5108    pub is_block: bool,
5109}
5110
5111// ============================================================================
5112// Additional Predicate types
5113// ============================================================================
5114
5115/// SIMILAR TO expression
5116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5117#[cfg_attr(feature = "bindings", derive(TS))]
5118pub struct SimilarToExpr {
5119    pub this: Expression,
5120    pub pattern: Expression,
5121    pub escape: Option<Expression>,
5122    pub not: bool,
5123}
5124
5125/// ANY / ALL quantified expression
5126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5127#[cfg_attr(feature = "bindings", derive(TS))]
5128pub struct QuantifiedExpr {
5129    pub this: Expression,
5130    pub subquery: Expression,
5131    pub op: Option<QuantifiedOp>,
5132}
5133
5134/// Comparison operator for quantified expressions
5135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5136#[cfg_attr(feature = "bindings", derive(TS))]
5137pub enum QuantifiedOp {
5138    Eq,
5139    Neq,
5140    Lt,
5141    Lte,
5142    Gt,
5143    Gte,
5144}
5145
5146/// OVERLAPS expression
5147/// Supports two forms:
5148/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5149/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5151#[cfg_attr(feature = "bindings", derive(TS))]
5152pub struct OverlapsExpr {
5153    /// Left operand for simple binary form
5154    #[serde(skip_serializing_if = "Option::is_none")]
5155    pub this: Option<Expression>,
5156    /// Right operand for simple binary form
5157    #[serde(skip_serializing_if = "Option::is_none")]
5158    pub expression: Option<Expression>,
5159    /// Left range start for full ANSI form
5160    #[serde(skip_serializing_if = "Option::is_none")]
5161    pub left_start: Option<Expression>,
5162    /// Left range end for full ANSI form
5163    #[serde(skip_serializing_if = "Option::is_none")]
5164    pub left_end: Option<Expression>,
5165    /// Right range start for full ANSI form
5166    #[serde(skip_serializing_if = "Option::is_none")]
5167    pub right_start: Option<Expression>,
5168    /// Right range end for full ANSI form
5169    #[serde(skip_serializing_if = "Option::is_none")]
5170    pub right_end: Option<Expression>,
5171}
5172
5173// ============================================================================
5174// Array/Struct/Map access
5175// ============================================================================
5176
5177/// Subscript access (array[index] or map[key])
5178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5179#[cfg_attr(feature = "bindings", derive(TS))]
5180pub struct Subscript {
5181    pub this: Expression,
5182    pub index: Expression,
5183}
5184
5185/// Dot access (struct.field)
5186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5187#[cfg_attr(feature = "bindings", derive(TS))]
5188pub struct DotAccess {
5189    pub this: Expression,
5190    pub field: Identifier,
5191}
5192
5193/// Method call (expr.method(args))
5194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5195#[cfg_attr(feature = "bindings", derive(TS))]
5196pub struct MethodCall {
5197    pub this: Expression,
5198    pub method: Identifier,
5199    pub args: Vec<Expression>,
5200}
5201
5202/// Array slice (array[start:end])
5203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5204#[cfg_attr(feature = "bindings", derive(TS))]
5205pub struct ArraySlice {
5206    pub this: Expression,
5207    pub start: Option<Expression>,
5208    pub end: Option<Expression>,
5209}
5210
5211// ============================================================================
5212// DDL (Data Definition Language) Statements
5213// ============================================================================
5214
5215/// ON COMMIT behavior for temporary tables
5216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5217#[cfg_attr(feature = "bindings", derive(TS))]
5218pub enum OnCommit {
5219    /// ON COMMIT PRESERVE ROWS
5220    PreserveRows,
5221    /// ON COMMIT DELETE ROWS
5222    DeleteRows,
5223}
5224
5225/// CREATE TABLE statement
5226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5227#[cfg_attr(feature = "bindings", derive(TS))]
5228pub struct CreateTable {
5229    pub name: TableRef,
5230    /// ClickHouse: ON CLUSTER clause for distributed DDL
5231    #[serde(default, skip_serializing_if = "Option::is_none")]
5232    pub on_cluster: Option<OnCluster>,
5233    pub columns: Vec<ColumnDef>,
5234    pub constraints: Vec<TableConstraint>,
5235    pub if_not_exists: bool,
5236    pub temporary: bool,
5237    pub or_replace: bool,
5238    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5239    #[serde(default, skip_serializing_if = "Option::is_none")]
5240    pub table_modifier: Option<String>,
5241    pub as_select: Option<Expression>,
5242    /// Whether the AS SELECT was wrapped in parentheses
5243    #[serde(default)]
5244    pub as_select_parenthesized: bool,
5245    /// ON COMMIT behavior for temporary tables
5246    #[serde(default)]
5247    pub on_commit: Option<OnCommit>,
5248    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5249    #[serde(default)]
5250    pub clone_source: Option<TableRef>,
5251    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5252    #[serde(default, skip_serializing_if = "Option::is_none")]
5253    pub clone_at_clause: Option<Expression>,
5254    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5255    #[serde(default)]
5256    pub is_copy: bool,
5257    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5258    #[serde(default)]
5259    pub shallow_clone: bool,
5260    /// Leading comments before the statement
5261    #[serde(default)]
5262    pub leading_comments: Vec<String>,
5263    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5264    #[serde(default)]
5265    pub with_properties: Vec<(String, String)>,
5266    /// Teradata: table options after name before columns (comma-separated)
5267    #[serde(default)]
5268    pub teradata_post_name_options: Vec<String>,
5269    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5270    #[serde(default)]
5271    pub with_data: Option<bool>,
5272    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5273    #[serde(default)]
5274    pub with_statistics: Option<bool>,
5275    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5276    #[serde(default)]
5277    pub teradata_indexes: Vec<TeradataIndex>,
5278    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5279    #[serde(default)]
5280    pub with_cte: Option<With>,
5281    /// Table properties like DEFAULT COLLATE (BigQuery)
5282    #[serde(default)]
5283    pub properties: Vec<Expression>,
5284    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5285    #[serde(default, skip_serializing_if = "Option::is_none")]
5286    pub partition_of: Option<Expression>,
5287    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5288    #[serde(default)]
5289    pub post_table_properties: Vec<Expression>,
5290    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5291    #[serde(default)]
5292    pub mysql_table_options: Vec<(String, String)>,
5293    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5294    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5295    pub inherits: Vec<TableRef>,
5296    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5297    #[serde(default, skip_serializing_if = "Option::is_none")]
5298    pub on_property: Option<OnProperty>,
5299    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5300    #[serde(default)]
5301    pub copy_grants: bool,
5302    /// Snowflake: USING TEMPLATE expression for schema inference
5303    #[serde(default, skip_serializing_if = "Option::is_none")]
5304    pub using_template: Option<Box<Expression>>,
5305    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5306    #[serde(default, skip_serializing_if = "Option::is_none")]
5307    pub rollup: Option<RollupProperty>,
5308}
5309
5310/// Teradata index specification for CREATE TABLE
5311#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5312#[cfg_attr(feature = "bindings", derive(TS))]
5313pub struct TeradataIndex {
5314    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5315    pub kind: TeradataIndexKind,
5316    /// Optional index name
5317    pub name: Option<String>,
5318    /// Optional column list
5319    pub columns: Vec<String>,
5320}
5321
5322/// Kind of Teradata index
5323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5324#[cfg_attr(feature = "bindings", derive(TS))]
5325pub enum TeradataIndexKind {
5326    /// NO PRIMARY INDEX
5327    NoPrimary,
5328    /// PRIMARY INDEX
5329    Primary,
5330    /// PRIMARY AMP INDEX
5331    PrimaryAmp,
5332    /// UNIQUE INDEX
5333    Unique,
5334    /// UNIQUE PRIMARY INDEX
5335    UniquePrimary,
5336    /// INDEX (secondary, non-primary)
5337    Secondary,
5338}
5339
5340impl CreateTable {
5341    pub fn new(name: impl Into<String>) -> Self {
5342        Self {
5343            name: TableRef::new(name),
5344            on_cluster: None,
5345            columns: Vec::new(),
5346            constraints: Vec::new(),
5347            if_not_exists: false,
5348            temporary: false,
5349            or_replace: false,
5350            table_modifier: None,
5351            as_select: None,
5352            as_select_parenthesized: false,
5353            on_commit: None,
5354            clone_source: None,
5355            clone_at_clause: None,
5356            shallow_clone: false,
5357            is_copy: false,
5358            leading_comments: Vec::new(),
5359            with_properties: Vec::new(),
5360            teradata_post_name_options: Vec::new(),
5361            with_data: None,
5362            with_statistics: None,
5363            teradata_indexes: Vec::new(),
5364            with_cte: None,
5365            properties: Vec::new(),
5366            partition_of: None,
5367            post_table_properties: Vec::new(),
5368            mysql_table_options: Vec::new(),
5369            inherits: Vec::new(),
5370            on_property: None,
5371            copy_grants: false,
5372            using_template: None,
5373            rollup: None,
5374        }
5375    }
5376}
5377
5378/// Sort order for PRIMARY KEY ASC/DESC
5379#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5380#[cfg_attr(feature = "bindings", derive(TS))]
5381pub enum SortOrder {
5382    Asc,
5383    Desc,
5384}
5385
5386/// Type of column constraint for tracking order
5387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5388#[cfg_attr(feature = "bindings", derive(TS))]
5389pub enum ConstraintType {
5390    NotNull,
5391    Null,
5392    PrimaryKey,
5393    Unique,
5394    Default,
5395    AutoIncrement,
5396    Collate,
5397    Comment,
5398    References,
5399    Check,
5400    GeneratedAsIdentity,
5401    /// Snowflake: TAG (key='value', ...)
5402    Tags,
5403    /// Computed/generated column
5404    ComputedColumn,
5405    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5406    GeneratedAsRow,
5407    /// MySQL: ON UPDATE expression
5408    OnUpdate,
5409    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5410    Path,
5411    /// Redshift: ENCODE encoding_type
5412    Encode,
5413}
5414
5415/// Column definition in CREATE TABLE
5416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5417#[cfg_attr(feature = "bindings", derive(TS))]
5418pub struct ColumnDef {
5419    pub name: Identifier,
5420    pub data_type: DataType,
5421    pub nullable: Option<bool>,
5422    pub default: Option<Expression>,
5423    pub primary_key: bool,
5424    /// Sort order for PRIMARY KEY (ASC/DESC)
5425    #[serde(default)]
5426    pub primary_key_order: Option<SortOrder>,
5427    pub unique: bool,
5428    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5429    #[serde(default)]
5430    pub unique_nulls_not_distinct: bool,
5431    pub auto_increment: bool,
5432    pub comment: Option<String>,
5433    pub constraints: Vec<ColumnConstraint>,
5434    /// Track original order of constraints for accurate regeneration
5435    #[serde(default)]
5436    pub constraint_order: Vec<ConstraintType>,
5437    /// Teradata: FORMAT 'pattern'
5438    #[serde(default)]
5439    pub format: Option<String>,
5440    /// Teradata: TITLE 'title'
5441    #[serde(default)]
5442    pub title: Option<String>,
5443    /// Teradata: INLINE LENGTH n
5444    #[serde(default)]
5445    pub inline_length: Option<u64>,
5446    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5447    #[serde(default)]
5448    pub compress: Option<Vec<Expression>>,
5449    /// Teradata: CHARACTER SET name
5450    #[serde(default)]
5451    pub character_set: Option<String>,
5452    /// Teradata: UPPERCASE
5453    #[serde(default)]
5454    pub uppercase: bool,
5455    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5456    #[serde(default)]
5457    pub casespecific: Option<bool>,
5458    /// Snowflake: AUTOINCREMENT START value
5459    #[serde(default)]
5460    pub auto_increment_start: Option<Box<Expression>>,
5461    /// Snowflake: AUTOINCREMENT INCREMENT value
5462    #[serde(default)]
5463    pub auto_increment_increment: Option<Box<Expression>>,
5464    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5465    #[serde(default)]
5466    pub auto_increment_order: Option<bool>,
5467    /// MySQL: UNSIGNED modifier
5468    #[serde(default)]
5469    pub unsigned: bool,
5470    /// MySQL: ZEROFILL modifier
5471    #[serde(default)]
5472    pub zerofill: bool,
5473    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5474    #[serde(default, skip_serializing_if = "Option::is_none")]
5475    pub on_update: Option<Expression>,
5476    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5477    #[serde(default, skip_serializing_if = "Option::is_none")]
5478    pub unique_constraint_name: Option<String>,
5479    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5480    #[serde(default, skip_serializing_if = "Option::is_none")]
5481    pub not_null_constraint_name: Option<String>,
5482    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5483    #[serde(default, skip_serializing_if = "Option::is_none")]
5484    pub primary_key_constraint_name: Option<String>,
5485    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5486    #[serde(default, skip_serializing_if = "Option::is_none")]
5487    pub check_constraint_name: Option<String>,
5488    /// BigQuery: OPTIONS (key=value, ...) on column
5489    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5490    pub options: Vec<Expression>,
5491    /// SQLite: Column definition without explicit type
5492    #[serde(default)]
5493    pub no_type: bool,
5494    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5495    #[serde(default, skip_serializing_if = "Option::is_none")]
5496    pub encoding: Option<String>,
5497    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5498    #[serde(default, skip_serializing_if = "Option::is_none")]
5499    pub codec: Option<String>,
5500    /// ClickHouse: EPHEMERAL [expr] modifier
5501    #[serde(default, skip_serializing_if = "Option::is_none")]
5502    pub ephemeral: Option<Option<Box<Expression>>>,
5503    /// ClickHouse: MATERIALIZED expr modifier
5504    #[serde(default, skip_serializing_if = "Option::is_none")]
5505    pub materialized_expr: Option<Box<Expression>>,
5506    /// ClickHouse: ALIAS expr modifier
5507    #[serde(default, skip_serializing_if = "Option::is_none")]
5508    pub alias_expr: Option<Box<Expression>>,
5509    /// ClickHouse: TTL expr modifier on columns
5510    #[serde(default, skip_serializing_if = "Option::is_none")]
5511    pub ttl_expr: Option<Box<Expression>>,
5512    /// TSQL: NOT FOR REPLICATION
5513    #[serde(default)]
5514    pub not_for_replication: bool,
5515}
5516
5517impl ColumnDef {
5518    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
5519        Self {
5520            name: Identifier::new(name),
5521            data_type,
5522            nullable: None,
5523            default: None,
5524            primary_key: false,
5525            primary_key_order: None,
5526            unique: false,
5527            unique_nulls_not_distinct: false,
5528            auto_increment: false,
5529            comment: None,
5530            constraints: Vec::new(),
5531            constraint_order: Vec::new(),
5532            format: None,
5533            title: None,
5534            inline_length: None,
5535            compress: None,
5536            character_set: None,
5537            uppercase: false,
5538            casespecific: None,
5539            auto_increment_start: None,
5540            auto_increment_increment: None,
5541            auto_increment_order: None,
5542            unsigned: false,
5543            zerofill: false,
5544            on_update: None,
5545            unique_constraint_name: None,
5546            not_null_constraint_name: None,
5547            primary_key_constraint_name: None,
5548            check_constraint_name: None,
5549            options: Vec::new(),
5550            no_type: false,
5551            encoding: None,
5552            codec: None,
5553            ephemeral: None,
5554            materialized_expr: None,
5555            alias_expr: None,
5556            ttl_expr: None,
5557            not_for_replication: false,
5558        }
5559    }
5560}
5561
5562/// Column-level constraint
5563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5564#[cfg_attr(feature = "bindings", derive(TS))]
5565pub enum ColumnConstraint {
5566    NotNull,
5567    Null,
5568    Unique,
5569    PrimaryKey,
5570    Default(Expression),
5571    Check(Expression),
5572    References(ForeignKeyRef),
5573    GeneratedAsIdentity(GeneratedAsIdentity),
5574    Collate(Identifier),
5575    Comment(String),
5576    /// Snowflake: TAG (key='value', ...)
5577    Tags(Tags),
5578    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
5579    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
5580    ComputedColumn(ComputedColumn),
5581    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5582    GeneratedAsRow(GeneratedAsRow),
5583    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
5584    Path(Expression),
5585}
5586
5587/// Computed/generated column constraint
5588#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5589#[cfg_attr(feature = "bindings", derive(TS))]
5590pub struct ComputedColumn {
5591    /// The expression that computes the column value
5592    pub expression: Box<Expression>,
5593    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
5594    #[serde(default)]
5595    pub persisted: bool,
5596    /// NOT NULL (TSQL computed columns)
5597    #[serde(default)]
5598    pub not_null: bool,
5599    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
5600    /// When None, defaults to dialect-appropriate output
5601    #[serde(default)]
5602    pub persistence_kind: Option<String>,
5603    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
5604    #[serde(default, skip_serializing_if = "Option::is_none")]
5605    pub data_type: Option<DataType>,
5606}
5607
5608/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5610#[cfg_attr(feature = "bindings", derive(TS))]
5611pub struct GeneratedAsRow {
5612    /// true = ROW START, false = ROW END
5613    pub start: bool,
5614    /// HIDDEN modifier
5615    #[serde(default)]
5616    pub hidden: bool,
5617}
5618
5619/// Generated identity column constraint
5620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5621#[cfg_attr(feature = "bindings", derive(TS))]
5622pub struct GeneratedAsIdentity {
5623    /// True for ALWAYS, False for BY DEFAULT
5624    pub always: bool,
5625    /// ON NULL (only valid with BY DEFAULT)
5626    pub on_null: bool,
5627    /// START WITH value
5628    pub start: Option<Box<Expression>>,
5629    /// INCREMENT BY value
5630    pub increment: Option<Box<Expression>>,
5631    /// MINVALUE
5632    pub minvalue: Option<Box<Expression>>,
5633    /// MAXVALUE
5634    pub maxvalue: Option<Box<Expression>>,
5635    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
5636    pub cycle: Option<bool>,
5637}
5638
5639/// Constraint modifiers (shared between table-level constraints)
5640#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5641#[cfg_attr(feature = "bindings", derive(TS))]
5642pub struct ConstraintModifiers {
5643    /// ENFORCED / NOT ENFORCED
5644    pub enforced: Option<bool>,
5645    /// DEFERRABLE / NOT DEFERRABLE
5646    pub deferrable: Option<bool>,
5647    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
5648    pub initially_deferred: Option<bool>,
5649    /// NORELY (Oracle)
5650    pub norely: bool,
5651    /// RELY (Oracle)
5652    pub rely: bool,
5653    /// USING index type (MySQL): BTREE or HASH
5654    #[serde(default)]
5655    pub using: Option<String>,
5656    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
5657    #[serde(default)]
5658    pub using_before_columns: bool,
5659    /// MySQL index COMMENT 'text'
5660    #[serde(default, skip_serializing_if = "Option::is_none")]
5661    pub comment: Option<String>,
5662    /// MySQL index VISIBLE/INVISIBLE
5663    #[serde(default, skip_serializing_if = "Option::is_none")]
5664    pub visible: Option<bool>,
5665    /// MySQL ENGINE_ATTRIBUTE = 'value'
5666    #[serde(default, skip_serializing_if = "Option::is_none")]
5667    pub engine_attribute: Option<String>,
5668    /// MySQL WITH PARSER name
5669    #[serde(default, skip_serializing_if = "Option::is_none")]
5670    pub with_parser: Option<String>,
5671    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
5672    #[serde(default)]
5673    pub not_valid: bool,
5674    /// TSQL CLUSTERED/NONCLUSTERED modifier
5675    #[serde(default, skip_serializing_if = "Option::is_none")]
5676    pub clustered: Option<String>,
5677    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
5678    #[serde(default, skip_serializing_if = "Option::is_none")]
5679    pub on_conflict: Option<String>,
5680    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
5681    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5682    pub with_options: Vec<(String, String)>,
5683    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
5684    #[serde(default, skip_serializing_if = "Option::is_none")]
5685    pub on_filegroup: Option<Identifier>,
5686}
5687
5688/// Table-level constraint
5689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5690#[cfg_attr(feature = "bindings", derive(TS))]
5691pub enum TableConstraint {
5692    PrimaryKey {
5693        name: Option<Identifier>,
5694        columns: Vec<Identifier>,
5695        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
5696        #[serde(default)]
5697        include_columns: Vec<Identifier>,
5698        #[serde(default)]
5699        modifiers: ConstraintModifiers,
5700        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
5701        #[serde(default)]
5702        has_constraint_keyword: bool,
5703    },
5704    Unique {
5705        name: Option<Identifier>,
5706        columns: Vec<Identifier>,
5707        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
5708        #[serde(default)]
5709        columns_parenthesized: bool,
5710        #[serde(default)]
5711        modifiers: ConstraintModifiers,
5712        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
5713        #[serde(default)]
5714        has_constraint_keyword: bool,
5715        /// PostgreSQL 15+: NULLS NOT DISTINCT
5716        #[serde(default)]
5717        nulls_not_distinct: bool,
5718    },
5719    ForeignKey {
5720        name: Option<Identifier>,
5721        columns: Vec<Identifier>,
5722        #[serde(default)]
5723        references: Option<ForeignKeyRef>,
5724        /// ON DELETE action when REFERENCES is absent
5725        #[serde(default)]
5726        on_delete: Option<ReferentialAction>,
5727        /// ON UPDATE action when REFERENCES is absent
5728        #[serde(default)]
5729        on_update: Option<ReferentialAction>,
5730        #[serde(default)]
5731        modifiers: ConstraintModifiers,
5732    },
5733    Check {
5734        name: Option<Identifier>,
5735        expression: Expression,
5736        #[serde(default)]
5737        modifiers: ConstraintModifiers,
5738    },
5739    /// INDEX / KEY constraint (MySQL)
5740    Index {
5741        name: Option<Identifier>,
5742        columns: Vec<Identifier>,
5743        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
5744        #[serde(default)]
5745        kind: Option<String>,
5746        #[serde(default)]
5747        modifiers: ConstraintModifiers,
5748        /// True if KEY keyword was used instead of INDEX
5749        #[serde(default)]
5750        use_key_keyword: bool,
5751        /// ClickHouse: indexed expression (instead of columns)
5752        #[serde(default, skip_serializing_if = "Option::is_none")]
5753        expression: Option<Box<Expression>>,
5754        /// ClickHouse: TYPE type_func(args)
5755        #[serde(default, skip_serializing_if = "Option::is_none")]
5756        index_type: Option<Box<Expression>>,
5757        /// ClickHouse: GRANULARITY n
5758        #[serde(default, skip_serializing_if = "Option::is_none")]
5759        granularity: Option<Box<Expression>>,
5760    },
5761    /// ClickHouse PROJECTION definition
5762    Projection {
5763        name: Identifier,
5764        expression: Expression,
5765    },
5766    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
5767    Like {
5768        source: TableRef,
5769        /// Options as (INCLUDING|EXCLUDING, property) pairs
5770        options: Vec<(LikeOptionAction, String)>,
5771    },
5772    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
5773    PeriodForSystemTime {
5774        start_col: Identifier,
5775        end_col: Identifier,
5776    },
5777    /// PostgreSQL EXCLUDE constraint
5778    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
5779    Exclude {
5780        name: Option<Identifier>,
5781        /// Index access method (gist, btree, etc.)
5782        #[serde(default)]
5783        using: Option<String>,
5784        /// Elements: (expression, operator) pairs
5785        elements: Vec<ExcludeElement>,
5786        /// INCLUDE columns
5787        #[serde(default)]
5788        include_columns: Vec<Identifier>,
5789        /// WHERE predicate
5790        #[serde(default)]
5791        where_clause: Option<Box<Expression>>,
5792        /// WITH (storage_parameters)
5793        #[serde(default)]
5794        with_params: Vec<(String, String)>,
5795        /// USING INDEX TABLESPACE tablespace_name
5796        #[serde(default)]
5797        using_index_tablespace: Option<String>,
5798        #[serde(default)]
5799        modifiers: ConstraintModifiers,
5800    },
5801    /// Snowflake TAG clause: TAG (key='value', key2='value2')
5802    Tags(Tags),
5803    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
5804    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
5805    /// for all deferrable constraints in the table
5806    InitiallyDeferred {
5807        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
5808        deferred: bool,
5809    },
5810}
5811
5812/// Element in an EXCLUDE constraint: expression WITH operator
5813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5814#[cfg_attr(feature = "bindings", derive(TS))]
5815pub struct ExcludeElement {
5816    /// The column expression (may include operator class, ordering, nulls)
5817    pub expression: String,
5818    /// The operator (e.g., &&, =)
5819    pub operator: String,
5820}
5821
5822/// Action for LIKE clause options
5823#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5824#[cfg_attr(feature = "bindings", derive(TS))]
5825pub enum LikeOptionAction {
5826    Including,
5827    Excluding,
5828}
5829
5830/// MATCH type for foreign keys
5831#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5832#[cfg_attr(feature = "bindings", derive(TS))]
5833pub enum MatchType {
5834    Full,
5835    Partial,
5836    Simple,
5837}
5838
5839/// Foreign key reference
5840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5841#[cfg_attr(feature = "bindings", derive(TS))]
5842pub struct ForeignKeyRef {
5843    pub table: TableRef,
5844    pub columns: Vec<Identifier>,
5845    pub on_delete: Option<ReferentialAction>,
5846    pub on_update: Option<ReferentialAction>,
5847    /// True if ON UPDATE appears before ON DELETE in the original SQL
5848    #[serde(default)]
5849    pub on_update_first: bool,
5850    /// MATCH clause (FULL, PARTIAL, SIMPLE)
5851    #[serde(default)]
5852    pub match_type: Option<MatchType>,
5853    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
5854    #[serde(default)]
5855    pub match_after_actions: bool,
5856    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
5857    #[serde(default)]
5858    pub constraint_name: Option<String>,
5859    /// DEFERRABLE / NOT DEFERRABLE
5860    #[serde(default)]
5861    pub deferrable: Option<bool>,
5862    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
5863    #[serde(default)]
5864    pub has_foreign_key_keywords: bool,
5865}
5866
5867/// Referential action for foreign keys
5868#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5869#[cfg_attr(feature = "bindings", derive(TS))]
5870pub enum ReferentialAction {
5871    Cascade,
5872    SetNull,
5873    SetDefault,
5874    Restrict,
5875    NoAction,
5876}
5877
5878/// DROP TABLE statement
5879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5880#[cfg_attr(feature = "bindings", derive(TS))]
5881pub struct DropTable {
5882    pub names: Vec<TableRef>,
5883    pub if_exists: bool,
5884    pub cascade: bool,
5885    /// Oracle: CASCADE CONSTRAINTS
5886    #[serde(default)]
5887    pub cascade_constraints: bool,
5888    /// Oracle: PURGE
5889    #[serde(default)]
5890    pub purge: bool,
5891    /// Comments that appear before the DROP keyword (e.g., leading line comments)
5892    #[serde(default)]
5893    pub leading_comments: Vec<String>,
5894}
5895
5896impl DropTable {
5897    pub fn new(name: impl Into<String>) -> Self {
5898        Self {
5899            names: vec![TableRef::new(name)],
5900            if_exists: false,
5901            cascade: false,
5902            cascade_constraints: false,
5903            purge: false,
5904            leading_comments: Vec::new(),
5905        }
5906    }
5907}
5908
5909/// ALTER TABLE statement
5910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5911#[cfg_attr(feature = "bindings", derive(TS))]
5912pub struct AlterTable {
5913    pub name: TableRef,
5914    pub actions: Vec<AlterTableAction>,
5915    /// IF EXISTS clause
5916    #[serde(default)]
5917    pub if_exists: bool,
5918    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
5919    #[serde(default, skip_serializing_if = "Option::is_none")]
5920    pub algorithm: Option<String>,
5921    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
5922    #[serde(default, skip_serializing_if = "Option::is_none")]
5923    pub lock: Option<String>,
5924    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
5925    #[serde(default, skip_serializing_if = "Option::is_none")]
5926    pub with_check: Option<String>,
5927    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
5928    #[serde(default, skip_serializing_if = "Option::is_none")]
5929    pub partition: Option<Vec<(Identifier, Expression)>>,
5930    /// ClickHouse: ON CLUSTER clause for distributed DDL
5931    #[serde(default, skip_serializing_if = "Option::is_none")]
5932    pub on_cluster: Option<OnCluster>,
5933}
5934
5935impl AlterTable {
5936    pub fn new(name: impl Into<String>) -> Self {
5937        Self {
5938            name: TableRef::new(name),
5939            actions: Vec::new(),
5940            if_exists: false,
5941            algorithm: None,
5942            lock: None,
5943            with_check: None,
5944            partition: None,
5945            on_cluster: None,
5946        }
5947    }
5948}
5949
5950/// Column position for ADD COLUMN (MySQL/MariaDB)
5951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5952#[cfg_attr(feature = "bindings", derive(TS))]
5953pub enum ColumnPosition {
5954    First,
5955    After(Identifier),
5956}
5957
5958/// Actions for ALTER TABLE
5959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5960#[cfg_attr(feature = "bindings", derive(TS))]
5961pub enum AlterTableAction {
5962    AddColumn {
5963        column: ColumnDef,
5964        if_not_exists: bool,
5965        position: Option<ColumnPosition>,
5966    },
5967    DropColumn {
5968        name: Identifier,
5969        if_exists: bool,
5970        cascade: bool,
5971    },
5972    RenameColumn {
5973        old_name: Identifier,
5974        new_name: Identifier,
5975        if_exists: bool,
5976    },
5977    AlterColumn {
5978        name: Identifier,
5979        action: AlterColumnAction,
5980        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
5981        #[serde(default)]
5982        use_modify_keyword: bool,
5983    },
5984    RenameTable(TableRef),
5985    AddConstraint(TableConstraint),
5986    DropConstraint {
5987        name: Identifier,
5988        if_exists: bool,
5989    },
5990    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
5991    DropForeignKey {
5992        name: Identifier,
5993    },
5994    /// DROP PARTITION action (Hive/BigQuery)
5995    DropPartition {
5996        /// List of partitions to drop (each partition is a list of key=value pairs)
5997        partitions: Vec<Vec<(Identifier, Expression)>>,
5998        if_exists: bool,
5999    },
6000    /// ADD PARTITION action (Hive/Spark)
6001    AddPartition {
6002        /// The partition expression
6003        partition: Expression,
6004        if_not_exists: bool,
6005        location: Option<Expression>,
6006    },
6007    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
6008    Delete {
6009        where_clause: Expression,
6010    },
6011    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
6012    SwapWith(TableRef),
6013    /// SET property action (Snowflake): ALTER TABLE t SET property=value
6014    SetProperty {
6015        properties: Vec<(String, Expression)>,
6016    },
6017    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
6018    UnsetProperty {
6019        properties: Vec<String>,
6020    },
6021    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
6022    ClusterBy {
6023        expressions: Vec<Expression>,
6024    },
6025    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
6026    SetTag {
6027        expressions: Vec<(String, Expression)>,
6028    },
6029    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
6030    UnsetTag {
6031        names: Vec<String>,
6032    },
6033    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6034    SetOptions {
6035        expressions: Vec<Expression>,
6036    },
6037    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6038    AlterIndex {
6039        name: Identifier,
6040        visible: bool,
6041    },
6042    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6043    SetAttribute {
6044        attribute: String,
6045    },
6046    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6047    SetStageFileFormat {
6048        options: Option<Expression>,
6049    },
6050    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6051    SetStageCopyOptions {
6052        options: Option<Expression>,
6053    },
6054    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6055    AddColumns {
6056        columns: Vec<ColumnDef>,
6057        cascade: bool,
6058    },
6059    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6060    DropColumns {
6061        names: Vec<Identifier>,
6062    },
6063    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6064    /// In SingleStore, data_type can be omitted for simple column renames
6065    ChangeColumn {
6066        old_name: Identifier,
6067        new_name: Identifier,
6068        #[serde(default, skip_serializing_if = "Option::is_none")]
6069        data_type: Option<DataType>,
6070        comment: Option<String>,
6071        #[serde(default)]
6072        cascade: bool,
6073    },
6074    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6075    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6076    AlterSortKey {
6077        /// AUTO or NONE keyword
6078        this: Option<String>,
6079        /// Column list for (col1, col2) syntax
6080        expressions: Vec<Expression>,
6081        /// Whether COMPOUND keyword was present
6082        compound: bool,
6083    },
6084    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6085    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6086    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6087    AlterDistStyle {
6088        /// Distribution style: ALL, EVEN, AUTO, or KEY
6089        style: String,
6090        /// DISTKEY column (only when style is KEY)
6091        distkey: Option<Identifier>,
6092    },
6093    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6094    SetTableProperties {
6095        properties: Vec<(Expression, Expression)>,
6096    },
6097    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6098    SetLocation {
6099        location: String,
6100    },
6101    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6102    SetFileFormat {
6103        format: String,
6104    },
6105    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6106    ReplacePartition {
6107        partition: Expression,
6108        source: Option<Box<Expression>>,
6109    },
6110    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6111    Raw {
6112        sql: String,
6113    },
6114}
6115
6116/// Actions for ALTER COLUMN
6117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6118#[cfg_attr(feature = "bindings", derive(TS))]
6119pub enum AlterColumnAction {
6120    SetDataType {
6121        data_type: DataType,
6122        /// USING expression for type conversion (PostgreSQL)
6123        using: Option<Expression>,
6124        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6125        #[serde(default, skip_serializing_if = "Option::is_none")]
6126        collate: Option<String>,
6127    },
6128    SetDefault(Expression),
6129    DropDefault,
6130    SetNotNull,
6131    DropNotNull,
6132    /// Set column comment
6133    Comment(String),
6134    /// MySQL: SET VISIBLE
6135    SetVisible,
6136    /// MySQL: SET INVISIBLE
6137    SetInvisible,
6138}
6139
6140/// CREATE INDEX statement
6141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6142#[cfg_attr(feature = "bindings", derive(TS))]
6143pub struct CreateIndex {
6144    pub name: Identifier,
6145    pub table: TableRef,
6146    pub columns: Vec<IndexColumn>,
6147    pub unique: bool,
6148    pub if_not_exists: bool,
6149    pub using: Option<String>,
6150    /// TSQL CLUSTERED/NONCLUSTERED modifier
6151    #[serde(default)]
6152    pub clustered: Option<String>,
6153    /// PostgreSQL CONCURRENTLY modifier
6154    #[serde(default)]
6155    pub concurrently: bool,
6156    /// PostgreSQL WHERE clause for partial indexes
6157    #[serde(default)]
6158    pub where_clause: Option<Box<Expression>>,
6159    /// PostgreSQL INCLUDE columns
6160    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6161    pub include_columns: Vec<Identifier>,
6162    /// TSQL WITH options (e.g., allow_page_locks=on)
6163    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6164    pub with_options: Vec<(String, String)>,
6165    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6166    #[serde(default)]
6167    pub on_filegroup: Option<String>,
6168}
6169
6170impl CreateIndex {
6171    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6172        Self {
6173            name: Identifier::new(name),
6174            table: TableRef::new(table),
6175            columns: Vec::new(),
6176            unique: false,
6177            if_not_exists: false,
6178            using: None,
6179            clustered: None,
6180            concurrently: false,
6181            where_clause: None,
6182            include_columns: Vec::new(),
6183            with_options: Vec::new(),
6184            on_filegroup: None,
6185        }
6186    }
6187}
6188
6189/// Index column specification
6190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6191#[cfg_attr(feature = "bindings", derive(TS))]
6192pub struct IndexColumn {
6193    pub column: Identifier,
6194    pub desc: bool,
6195    /// Explicit ASC keyword was present
6196    #[serde(default)]
6197    pub asc: bool,
6198    pub nulls_first: Option<bool>,
6199    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6200    #[serde(default, skip_serializing_if = "Option::is_none")]
6201    pub opclass: Option<String>,
6202}
6203
6204/// DROP INDEX statement
6205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6206#[cfg_attr(feature = "bindings", derive(TS))]
6207pub struct DropIndex {
6208    pub name: Identifier,
6209    pub table: Option<TableRef>,
6210    pub if_exists: bool,
6211    /// PostgreSQL CONCURRENTLY modifier
6212    #[serde(default)]
6213    pub concurrently: bool,
6214}
6215
6216impl DropIndex {
6217    pub fn new(name: impl Into<String>) -> Self {
6218        Self {
6219            name: Identifier::new(name),
6220            table: None,
6221            if_exists: false,
6222            concurrently: false,
6223        }
6224    }
6225}
6226
6227/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6229#[cfg_attr(feature = "bindings", derive(TS))]
6230pub struct ViewColumn {
6231    pub name: Identifier,
6232    pub comment: Option<String>,
6233    /// BigQuery: OPTIONS (key=value, ...) on column
6234    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6235    pub options: Vec<Expression>,
6236}
6237
6238impl ViewColumn {
6239    pub fn new(name: impl Into<String>) -> Self {
6240        Self {
6241            name: Identifier::new(name),
6242            comment: None,
6243            options: Vec::new(),
6244        }
6245    }
6246
6247    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6248        Self {
6249            name: Identifier::new(name),
6250            comment: Some(comment.into()),
6251            options: Vec::new(),
6252        }
6253    }
6254}
6255
6256/// CREATE VIEW statement
6257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6258#[cfg_attr(feature = "bindings", derive(TS))]
6259pub struct CreateView {
6260    pub name: TableRef,
6261    pub columns: Vec<ViewColumn>,
6262    pub query: Expression,
6263    pub or_replace: bool,
6264    pub if_not_exists: bool,
6265    pub materialized: bool,
6266    pub temporary: bool,
6267    /// Snowflake: SECURE VIEW
6268    #[serde(default)]
6269    pub secure: bool,
6270    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6271    #[serde(skip_serializing_if = "Option::is_none")]
6272    pub algorithm: Option<String>,
6273    /// MySQL: DEFINER=user@host
6274    #[serde(skip_serializing_if = "Option::is_none")]
6275    pub definer: Option<String>,
6276    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6277    #[serde(skip_serializing_if = "Option::is_none")]
6278    pub security: Option<FunctionSecurity>,
6279    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6280    #[serde(default = "default_true")]
6281    pub security_sql_style: bool,
6282    /// Whether the query was parenthesized: AS (SELECT ...)
6283    #[serde(default)]
6284    pub query_parenthesized: bool,
6285    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6286    #[serde(skip_serializing_if = "Option::is_none")]
6287    pub locking_mode: Option<String>,
6288    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6289    #[serde(skip_serializing_if = "Option::is_none")]
6290    pub locking_access: Option<String>,
6291    /// Snowflake: COPY GRANTS
6292    #[serde(default)]
6293    pub copy_grants: bool,
6294    /// Snowflake: COMMENT = 'text'
6295    #[serde(skip_serializing_if = "Option::is_none", default)]
6296    pub comment: Option<String>,
6297    /// Snowflake: TAG (name='value', ...)
6298    #[serde(default)]
6299    pub tags: Vec<(String, String)>,
6300    /// BigQuery: OPTIONS (key=value, ...)
6301    #[serde(default)]
6302    pub options: Vec<Expression>,
6303    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6304    #[serde(skip_serializing_if = "Option::is_none", default)]
6305    pub build: Option<String>,
6306    /// Doris: REFRESH property for materialized views
6307    #[serde(skip_serializing_if = "Option::is_none", default)]
6308    pub refresh: Option<Box<RefreshTriggerProperty>>,
6309    /// Doris: Schema with typed column definitions for materialized views
6310    /// This is used instead of `columns` when the view has typed column definitions
6311    #[serde(skip_serializing_if = "Option::is_none", default)]
6312    pub schema: Option<Box<Schema>>,
6313    /// Doris: KEY (columns) for materialized views
6314    #[serde(skip_serializing_if = "Option::is_none", default)]
6315    pub unique_key: Option<Box<UniqueKeyProperty>>,
6316    /// Redshift: WITH NO SCHEMA BINDING
6317    #[serde(default)]
6318    pub no_schema_binding: bool,
6319    /// Redshift: AUTO REFRESH YES|NO for materialized views
6320    #[serde(skip_serializing_if = "Option::is_none", default)]
6321    pub auto_refresh: Option<bool>,
6322    /// ClickHouse: ON CLUSTER clause
6323    #[serde(default, skip_serializing_if = "Option::is_none")]
6324    pub on_cluster: Option<OnCluster>,
6325    /// ClickHouse: TO destination_table
6326    #[serde(default, skip_serializing_if = "Option::is_none")]
6327    pub to_table: Option<TableRef>,
6328    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6329    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6330    pub table_properties: Vec<Expression>,
6331}
6332
6333impl CreateView {
6334    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6335        Self {
6336            name: TableRef::new(name),
6337            columns: Vec::new(),
6338            query,
6339            or_replace: false,
6340            if_not_exists: false,
6341            materialized: false,
6342            temporary: false,
6343            secure: false,
6344            algorithm: None,
6345            definer: None,
6346            security: None,
6347            security_sql_style: true,
6348            query_parenthesized: false,
6349            locking_mode: None,
6350            locking_access: None,
6351            copy_grants: false,
6352            comment: None,
6353            tags: Vec::new(),
6354            options: Vec::new(),
6355            build: None,
6356            refresh: None,
6357            schema: None,
6358            unique_key: None,
6359            no_schema_binding: false,
6360            auto_refresh: None,
6361            on_cluster: None,
6362            to_table: None,
6363            table_properties: Vec::new(),
6364        }
6365    }
6366}
6367
6368/// DROP VIEW statement
6369#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6370#[cfg_attr(feature = "bindings", derive(TS))]
6371pub struct DropView {
6372    pub name: TableRef,
6373    pub if_exists: bool,
6374    pub materialized: bool,
6375}
6376
6377impl DropView {
6378    pub fn new(name: impl Into<String>) -> Self {
6379        Self {
6380            name: TableRef::new(name),
6381            if_exists: false,
6382            materialized: false,
6383        }
6384    }
6385}
6386
6387/// TRUNCATE TABLE statement
6388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6389#[cfg_attr(feature = "bindings", derive(TS))]
6390pub struct Truncate {
6391    /// Target of TRUNCATE (TABLE vs DATABASE)
6392    #[serde(default)]
6393    pub target: TruncateTarget,
6394    /// IF EXISTS clause
6395    #[serde(default)]
6396    pub if_exists: bool,
6397    pub table: TableRef,
6398    /// ClickHouse: ON CLUSTER clause for distributed DDL
6399    #[serde(default, skip_serializing_if = "Option::is_none")]
6400    pub on_cluster: Option<OnCluster>,
6401    pub cascade: bool,
6402    /// Additional tables for multi-table TRUNCATE
6403    #[serde(default)]
6404    pub extra_tables: Vec<TruncateTableEntry>,
6405    /// RESTART IDENTITY or CONTINUE IDENTITY
6406    #[serde(default)]
6407    pub identity: Option<TruncateIdentity>,
6408    /// RESTRICT option (alternative to CASCADE)
6409    #[serde(default)]
6410    pub restrict: bool,
6411    /// Hive PARTITION clause: PARTITION(key=value, ...)
6412    #[serde(default, skip_serializing_if = "Option::is_none")]
6413    pub partition: Option<Box<Expression>>,
6414}
6415
6416/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6418#[cfg_attr(feature = "bindings", derive(TS))]
6419pub struct TruncateTableEntry {
6420    pub table: TableRef,
6421    /// Whether the table has a * suffix (inherit children)
6422    #[serde(default)]
6423    pub star: bool,
6424}
6425
6426/// TRUNCATE target type
6427#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6428#[cfg_attr(feature = "bindings", derive(TS))]
6429pub enum TruncateTarget {
6430    Table,
6431    Database,
6432}
6433
6434impl Default for TruncateTarget {
6435    fn default() -> Self {
6436        TruncateTarget::Table
6437    }
6438}
6439
6440/// TRUNCATE identity option
6441#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6442#[cfg_attr(feature = "bindings", derive(TS))]
6443pub enum TruncateIdentity {
6444    Restart,
6445    Continue,
6446}
6447
6448impl Truncate {
6449    pub fn new(table: impl Into<String>) -> Self {
6450        Self {
6451            target: TruncateTarget::Table,
6452            if_exists: false,
6453            table: TableRef::new(table),
6454            on_cluster: None,
6455            cascade: false,
6456            extra_tables: Vec::new(),
6457            identity: None,
6458            restrict: false,
6459            partition: None,
6460        }
6461    }
6462}
6463
6464/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6466#[cfg_attr(feature = "bindings", derive(TS))]
6467pub struct Use {
6468    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6469    pub kind: Option<UseKind>,
6470    /// The name of the object
6471    pub this: Identifier,
6472}
6473
6474/// Kind of USE statement
6475#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6476#[cfg_attr(feature = "bindings", derive(TS))]
6477pub enum UseKind {
6478    Database,
6479    Schema,
6480    Role,
6481    Warehouse,
6482    Catalog,
6483    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6484    SecondaryRoles,
6485}
6486
6487/// SET variable statement
6488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6489#[cfg_attr(feature = "bindings", derive(TS))]
6490pub struct SetStatement {
6491    /// The items being set
6492    pub items: Vec<SetItem>,
6493}
6494
6495/// A single SET item (variable assignment)
6496#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6497#[cfg_attr(feature = "bindings", derive(TS))]
6498pub struct SetItem {
6499    /// The variable name
6500    pub name: Expression,
6501    /// The value to set
6502    pub value: Expression,
6503    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
6504    pub kind: Option<String>,
6505    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
6506    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6507    pub no_equals: bool,
6508}
6509
6510/// CACHE TABLE statement (Spark)
6511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6512#[cfg_attr(feature = "bindings", derive(TS))]
6513pub struct Cache {
6514    /// The table to cache
6515    pub table: Identifier,
6516    /// LAZY keyword - defer caching until first use
6517    pub lazy: bool,
6518    /// Optional OPTIONS clause (key-value pairs)
6519    pub options: Vec<(Expression, Expression)>,
6520    /// Optional AS clause with query
6521    pub query: Option<Expression>,
6522}
6523
6524/// UNCACHE TABLE statement (Spark)
6525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6526#[cfg_attr(feature = "bindings", derive(TS))]
6527pub struct Uncache {
6528    /// The table to uncache
6529    pub table: Identifier,
6530    /// IF EXISTS clause
6531    pub if_exists: bool,
6532}
6533
6534/// LOAD DATA statement (Hive)
6535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6536#[cfg_attr(feature = "bindings", derive(TS))]
6537pub struct LoadData {
6538    /// LOCAL keyword - load from local filesystem
6539    pub local: bool,
6540    /// The path to load data from (INPATH value)
6541    pub inpath: String,
6542    /// Whether to overwrite existing data
6543    pub overwrite: bool,
6544    /// The target table
6545    pub table: Expression,
6546    /// Optional PARTITION clause with key-value pairs
6547    pub partition: Vec<(Identifier, Expression)>,
6548    /// Optional INPUTFORMAT clause
6549    pub input_format: Option<String>,
6550    /// Optional SERDE clause
6551    pub serde: Option<String>,
6552}
6553
6554/// PRAGMA statement (SQLite)
6555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6556#[cfg_attr(feature = "bindings", derive(TS))]
6557pub struct Pragma {
6558    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
6559    pub schema: Option<Identifier>,
6560    /// The pragma name
6561    pub name: Identifier,
6562    /// Optional value for assignment (PRAGMA name = value)
6563    pub value: Option<Expression>,
6564    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
6565    pub args: Vec<Expression>,
6566}
6567
6568/// A privilege with optional column list for GRANT/REVOKE
6569/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
6570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6571#[cfg_attr(feature = "bindings", derive(TS))]
6572pub struct Privilege {
6573    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
6574    pub name: String,
6575    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
6576    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6577    pub columns: Vec<String>,
6578}
6579
6580/// Principal in GRANT/REVOKE (user, role, etc.)
6581#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6582#[cfg_attr(feature = "bindings", derive(TS))]
6583pub struct GrantPrincipal {
6584    /// The name of the principal
6585    pub name: Identifier,
6586    /// Whether prefixed with ROLE keyword
6587    pub is_role: bool,
6588    /// Whether prefixed with GROUP keyword (Redshift)
6589    #[serde(default)]
6590    pub is_group: bool,
6591}
6592
6593/// GRANT statement
6594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6595#[cfg_attr(feature = "bindings", derive(TS))]
6596pub struct Grant {
6597    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
6598    pub privileges: Vec<Privilege>,
6599    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6600    pub kind: Option<String>,
6601    /// The object to grant on
6602    pub securable: Identifier,
6603    /// Function parameter types (for FUNCTION kind)
6604    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6605    pub function_params: Vec<String>,
6606    /// The grantees
6607    pub principals: Vec<GrantPrincipal>,
6608    /// WITH GRANT OPTION
6609    pub grant_option: bool,
6610    /// TSQL: AS principal (the grantor role)
6611    #[serde(default, skip_serializing_if = "Option::is_none")]
6612    pub as_principal: Option<Identifier>,
6613}
6614
6615/// REVOKE statement
6616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6617#[cfg_attr(feature = "bindings", derive(TS))]
6618pub struct Revoke {
6619    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
6620    pub privileges: Vec<Privilege>,
6621    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6622    pub kind: Option<String>,
6623    /// The object to revoke from
6624    pub securable: Identifier,
6625    /// Function parameter types (for FUNCTION kind)
6626    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6627    pub function_params: Vec<String>,
6628    /// The grantees
6629    pub principals: Vec<GrantPrincipal>,
6630    /// GRANT OPTION FOR
6631    pub grant_option: bool,
6632    /// CASCADE
6633    pub cascade: bool,
6634    /// RESTRICT
6635    #[serde(default)]
6636    pub restrict: bool,
6637}
6638
6639/// COMMENT ON statement
6640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6641#[cfg_attr(feature = "bindings", derive(TS))]
6642pub struct Comment {
6643    /// The object being commented on
6644    pub this: Expression,
6645    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
6646    pub kind: String,
6647    /// The comment text expression
6648    pub expression: Expression,
6649    /// IF EXISTS clause
6650    pub exists: bool,
6651    /// MATERIALIZED keyword
6652    pub materialized: bool,
6653}
6654
6655// ============================================================================
6656// Phase 4: Additional DDL Statements
6657// ============================================================================
6658
6659/// ALTER VIEW statement
6660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6661#[cfg_attr(feature = "bindings", derive(TS))]
6662pub struct AlterView {
6663    pub name: TableRef,
6664    pub actions: Vec<AlterViewAction>,
6665    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
6666    #[serde(default, skip_serializing_if = "Option::is_none")]
6667    pub algorithm: Option<String>,
6668    /// MySQL: DEFINER = 'user'@'host'
6669    #[serde(default, skip_serializing_if = "Option::is_none")]
6670    pub definer: Option<String>,
6671    /// MySQL: SQL SECURITY = DEFINER|INVOKER
6672    #[serde(default, skip_serializing_if = "Option::is_none")]
6673    pub sql_security: Option<String>,
6674    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
6675    #[serde(default, skip_serializing_if = "Option::is_none")]
6676    pub with_option: Option<String>,
6677    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
6678    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6679    pub columns: Vec<ViewColumn>,
6680}
6681
6682/// Actions for ALTER VIEW
6683#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6684#[cfg_attr(feature = "bindings", derive(TS))]
6685pub enum AlterViewAction {
6686    /// Rename the view
6687    Rename(TableRef),
6688    /// Change owner
6689    OwnerTo(Identifier),
6690    /// Set schema
6691    SetSchema(Identifier),
6692    /// Set authorization (Trino/Presto)
6693    SetAuthorization(String),
6694    /// Alter column
6695    AlterColumn {
6696        name: Identifier,
6697        action: AlterColumnAction,
6698    },
6699    /// Redefine view as query (SELECT, UNION, etc.)
6700    AsSelect(Box<Expression>),
6701    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
6702    SetTblproperties(Vec<(String, String)>),
6703    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
6704    UnsetTblproperties(Vec<String>),
6705}
6706
6707impl AlterView {
6708    pub fn new(name: impl Into<String>) -> Self {
6709        Self {
6710            name: TableRef::new(name),
6711            actions: Vec::new(),
6712            algorithm: None,
6713            definer: None,
6714            sql_security: None,
6715            with_option: None,
6716            columns: Vec::new(),
6717        }
6718    }
6719}
6720
6721/// ALTER INDEX statement
6722#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6723#[cfg_attr(feature = "bindings", derive(TS))]
6724pub struct AlterIndex {
6725    pub name: Identifier,
6726    pub table: Option<TableRef>,
6727    pub actions: Vec<AlterIndexAction>,
6728}
6729
6730/// Actions for ALTER INDEX
6731#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6732#[cfg_attr(feature = "bindings", derive(TS))]
6733pub enum AlterIndexAction {
6734    /// Rename the index
6735    Rename(Identifier),
6736    /// Set tablespace
6737    SetTablespace(Identifier),
6738    /// Set visibility (MySQL)
6739    Visible(bool),
6740}
6741
6742impl AlterIndex {
6743    pub fn new(name: impl Into<String>) -> Self {
6744        Self {
6745            name: Identifier::new(name),
6746            table: None,
6747            actions: Vec::new(),
6748        }
6749    }
6750}
6751
6752/// CREATE SCHEMA statement
6753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6754#[cfg_attr(feature = "bindings", derive(TS))]
6755pub struct CreateSchema {
6756    pub name: Identifier,
6757    pub if_not_exists: bool,
6758    pub authorization: Option<Identifier>,
6759    #[serde(default)]
6760    pub clone_from: Option<Identifier>,
6761    /// AT/BEFORE clause for time travel (Snowflake)
6762    #[serde(default)]
6763    pub at_clause: Option<Expression>,
6764    /// Schema properties like DEFAULT COLLATE
6765    #[serde(default)]
6766    pub properties: Vec<Expression>,
6767    /// Leading comments before the statement
6768    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6769    pub leading_comments: Vec<String>,
6770}
6771
6772impl CreateSchema {
6773    pub fn new(name: impl Into<String>) -> Self {
6774        Self {
6775            name: Identifier::new(name),
6776            if_not_exists: false,
6777            authorization: None,
6778            clone_from: None,
6779            at_clause: None,
6780            properties: Vec::new(),
6781            leading_comments: Vec::new(),
6782        }
6783    }
6784}
6785
6786/// DROP SCHEMA statement
6787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6788#[cfg_attr(feature = "bindings", derive(TS))]
6789pub struct DropSchema {
6790    pub name: Identifier,
6791    pub if_exists: bool,
6792    pub cascade: bool,
6793}
6794
6795impl DropSchema {
6796    pub fn new(name: impl Into<String>) -> Self {
6797        Self {
6798            name: Identifier::new(name),
6799            if_exists: false,
6800            cascade: false,
6801        }
6802    }
6803}
6804
6805/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
6806#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6807#[cfg_attr(feature = "bindings", derive(TS))]
6808pub struct DropNamespace {
6809    pub name: Identifier,
6810    pub if_exists: bool,
6811    pub cascade: bool,
6812}
6813
6814impl DropNamespace {
6815    pub fn new(name: impl Into<String>) -> Self {
6816        Self {
6817            name: Identifier::new(name),
6818            if_exists: false,
6819            cascade: false,
6820        }
6821    }
6822}
6823
6824/// CREATE DATABASE statement
6825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6826#[cfg_attr(feature = "bindings", derive(TS))]
6827pub struct CreateDatabase {
6828    pub name: Identifier,
6829    pub if_not_exists: bool,
6830    pub options: Vec<DatabaseOption>,
6831    /// Snowflake CLONE source
6832    #[serde(default)]
6833    pub clone_from: Option<Identifier>,
6834    /// AT/BEFORE clause for time travel (Snowflake)
6835    #[serde(default)]
6836    pub at_clause: Option<Expression>,
6837}
6838
6839/// Database option
6840#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6841#[cfg_attr(feature = "bindings", derive(TS))]
6842pub enum DatabaseOption {
6843    CharacterSet(String),
6844    Collate(String),
6845    Owner(Identifier),
6846    Template(Identifier),
6847    Encoding(String),
6848    Location(String),
6849}
6850
6851impl CreateDatabase {
6852    pub fn new(name: impl Into<String>) -> Self {
6853        Self {
6854            name: Identifier::new(name),
6855            if_not_exists: false,
6856            options: Vec::new(),
6857            clone_from: None,
6858            at_clause: None,
6859        }
6860    }
6861}
6862
6863/// DROP DATABASE statement
6864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6865#[cfg_attr(feature = "bindings", derive(TS))]
6866pub struct DropDatabase {
6867    pub name: Identifier,
6868    pub if_exists: bool,
6869}
6870
6871impl DropDatabase {
6872    pub fn new(name: impl Into<String>) -> Self {
6873        Self {
6874            name: Identifier::new(name),
6875            if_exists: false,
6876        }
6877    }
6878}
6879
6880/// CREATE FUNCTION statement
6881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6882#[cfg_attr(feature = "bindings", derive(TS))]
6883pub struct CreateFunction {
6884    pub name: TableRef,
6885    pub parameters: Vec<FunctionParameter>,
6886    pub return_type: Option<DataType>,
6887    pub body: Option<FunctionBody>,
6888    pub or_replace: bool,
6889    pub if_not_exists: bool,
6890    pub temporary: bool,
6891    pub language: Option<String>,
6892    pub deterministic: Option<bool>,
6893    pub returns_null_on_null_input: Option<bool>,
6894    pub security: Option<FunctionSecurity>,
6895    /// Whether parentheses were present in the original syntax
6896    #[serde(default = "default_true")]
6897    pub has_parens: bool,
6898    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
6899    #[serde(default)]
6900    pub sql_data_access: Option<SqlDataAccess>,
6901    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
6902    #[serde(default, skip_serializing_if = "Option::is_none")]
6903    pub returns_table_body: Option<String>,
6904    /// True if LANGUAGE clause appears before RETURNS clause
6905    #[serde(default)]
6906    pub language_first: bool,
6907    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
6908    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6909    pub set_options: Vec<FunctionSetOption>,
6910    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
6911    #[serde(default)]
6912    pub strict: bool,
6913    /// BigQuery: OPTIONS (key=value, ...)
6914    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6915    pub options: Vec<Expression>,
6916    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
6917    #[serde(default)]
6918    pub is_table_function: bool,
6919    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
6920    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6921    pub property_order: Vec<FunctionPropertyKind>,
6922    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
6923    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6924    pub environment: Vec<Expression>,
6925}
6926
6927/// A SET option in CREATE FUNCTION (PostgreSQL)
6928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6929#[cfg_attr(feature = "bindings", derive(TS))]
6930pub struct FunctionSetOption {
6931    pub name: String,
6932    pub value: FunctionSetValue,
6933}
6934
6935/// The value of a SET option
6936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6937#[cfg_attr(feature = "bindings", derive(TS))]
6938pub enum FunctionSetValue {
6939    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
6940    Value { value: String, use_to: bool },
6941    /// SET key FROM CURRENT
6942    FromCurrent,
6943}
6944
6945/// SQL data access characteristics for functions
6946#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6947#[cfg_attr(feature = "bindings", derive(TS))]
6948pub enum SqlDataAccess {
6949    /// NO SQL
6950    NoSql,
6951    /// CONTAINS SQL
6952    ContainsSql,
6953    /// READS SQL DATA
6954    ReadsSqlData,
6955    /// MODIFIES SQL DATA
6956    ModifiesSqlData,
6957}
6958
6959/// Types of properties in CREATE FUNCTION for tracking their original order
6960#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6961#[cfg_attr(feature = "bindings", derive(TS))]
6962pub enum FunctionPropertyKind {
6963    /// SET option
6964    Set,
6965    /// AS body
6966    As,
6967    /// LANGUAGE clause
6968    Language,
6969    /// IMMUTABLE/VOLATILE/STABLE (determinism)
6970    Determinism,
6971    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
6972    NullInput,
6973    /// SECURITY DEFINER/INVOKER
6974    Security,
6975    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
6976    SqlDataAccess,
6977    /// OPTIONS clause (BigQuery)
6978    Options,
6979    /// ENVIRONMENT clause (Databricks)
6980    Environment,
6981}
6982
6983/// Function parameter
6984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6985#[cfg_attr(feature = "bindings", derive(TS))]
6986pub struct FunctionParameter {
6987    pub name: Option<Identifier>,
6988    pub data_type: DataType,
6989    pub mode: Option<ParameterMode>,
6990    pub default: Option<Expression>,
6991    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
6992    #[serde(default, skip_serializing_if = "Option::is_none")]
6993    pub mode_text: Option<String>,
6994}
6995
6996/// Parameter mode (IN, OUT, INOUT, VARIADIC)
6997#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6998#[cfg_attr(feature = "bindings", derive(TS))]
6999pub enum ParameterMode {
7000    In,
7001    Out,
7002    InOut,
7003    Variadic,
7004}
7005
7006/// Function body
7007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7008#[cfg_attr(feature = "bindings", derive(TS))]
7009pub enum FunctionBody {
7010    /// AS $$ ... $$ (dollar-quoted)
7011    Block(String),
7012    /// AS 'string' (single-quoted string literal body)
7013    StringLiteral(String),
7014    /// AS 'expression'
7015    Expression(Expression),
7016    /// EXTERNAL NAME 'library'
7017    External(String),
7018    /// RETURN expression
7019    Return(Expression),
7020    /// BEGIN ... END block with parsed statements
7021    Statements(Vec<Expression>),
7022    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
7023    /// Stores (content, optional_tag)
7024    DollarQuoted {
7025        content: String,
7026        tag: Option<String>,
7027    },
7028}
7029
7030/// Function security (DEFINER, INVOKER, or NONE)
7031#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7032#[cfg_attr(feature = "bindings", derive(TS))]
7033pub enum FunctionSecurity {
7034    Definer,
7035    Invoker,
7036    /// StarRocks/MySQL: SECURITY NONE
7037    None,
7038}
7039
7040impl CreateFunction {
7041    pub fn new(name: impl Into<String>) -> Self {
7042        Self {
7043            name: TableRef::new(name),
7044            parameters: Vec::new(),
7045            return_type: None,
7046            body: None,
7047            or_replace: false,
7048            if_not_exists: false,
7049            temporary: false,
7050            language: None,
7051            deterministic: None,
7052            returns_null_on_null_input: None,
7053            security: None,
7054            has_parens: true,
7055            sql_data_access: None,
7056            returns_table_body: None,
7057            language_first: false,
7058            set_options: Vec::new(),
7059            strict: false,
7060            options: Vec::new(),
7061            is_table_function: false,
7062            property_order: Vec::new(),
7063            environment: Vec::new(),
7064        }
7065    }
7066}
7067
7068/// DROP FUNCTION statement
7069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7070#[cfg_attr(feature = "bindings", derive(TS))]
7071pub struct DropFunction {
7072    pub name: TableRef,
7073    pub parameters: Option<Vec<DataType>>,
7074    pub if_exists: bool,
7075    pub cascade: bool,
7076}
7077
7078impl DropFunction {
7079    pub fn new(name: impl Into<String>) -> Self {
7080        Self {
7081            name: TableRef::new(name),
7082            parameters: None,
7083            if_exists: false,
7084            cascade: false,
7085        }
7086    }
7087}
7088
7089/// CREATE PROCEDURE statement
7090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7091#[cfg_attr(feature = "bindings", derive(TS))]
7092pub struct CreateProcedure {
7093    pub name: TableRef,
7094    pub parameters: Vec<FunctionParameter>,
7095    pub body: Option<FunctionBody>,
7096    pub or_replace: bool,
7097    pub if_not_exists: bool,
7098    pub language: Option<String>,
7099    pub security: Option<FunctionSecurity>,
7100    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7101    #[serde(default)]
7102    pub return_type: Option<DataType>,
7103    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7104    #[serde(default)]
7105    pub execute_as: Option<String>,
7106    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7107    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7108    pub with_options: Vec<String>,
7109    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7110    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7111    pub has_parens: bool,
7112    /// Whether the short form PROC was used (instead of PROCEDURE)
7113    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7114    pub use_proc_keyword: bool,
7115}
7116
7117impl CreateProcedure {
7118    pub fn new(name: impl Into<String>) -> Self {
7119        Self {
7120            name: TableRef::new(name),
7121            parameters: Vec::new(),
7122            body: None,
7123            or_replace: false,
7124            if_not_exists: false,
7125            language: None,
7126            security: None,
7127            return_type: None,
7128            execute_as: None,
7129            with_options: Vec::new(),
7130            has_parens: true,
7131            use_proc_keyword: false,
7132        }
7133    }
7134}
7135
7136/// DROP PROCEDURE statement
7137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7138#[cfg_attr(feature = "bindings", derive(TS))]
7139pub struct DropProcedure {
7140    pub name: TableRef,
7141    pub parameters: Option<Vec<DataType>>,
7142    pub if_exists: bool,
7143    pub cascade: bool,
7144}
7145
7146impl DropProcedure {
7147    pub fn new(name: impl Into<String>) -> Self {
7148        Self {
7149            name: TableRef::new(name),
7150            parameters: None,
7151            if_exists: false,
7152            cascade: false,
7153        }
7154    }
7155}
7156
7157/// Sequence property tag for ordering
7158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7159#[cfg_attr(feature = "bindings", derive(TS))]
7160pub enum SeqPropKind {
7161    Start,
7162    Increment,
7163    Minvalue,
7164    Maxvalue,
7165    Cache,
7166    NoCache,
7167    Cycle,
7168    NoCycle,
7169    OwnedBy,
7170    Order,
7171    NoOrder,
7172    Comment,
7173    /// SHARING=<value> (Oracle)
7174    Sharing,
7175    /// KEEP (Oracle)
7176    Keep,
7177    /// NOKEEP (Oracle)
7178    NoKeep,
7179    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7180    Scale,
7181    /// NOSCALE (Oracle)
7182    NoScale,
7183    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7184    Shard,
7185    /// NOSHARD (Oracle)
7186    NoShard,
7187    /// SESSION (Oracle)
7188    Session,
7189    /// GLOBAL (Oracle)
7190    Global,
7191    /// NOCACHE (single word, Oracle)
7192    NoCacheWord,
7193    /// NOCYCLE (single word, Oracle)
7194    NoCycleWord,
7195    /// NOMINVALUE (single word, Oracle)
7196    NoMinvalueWord,
7197    /// NOMAXVALUE (single word, Oracle)
7198    NoMaxvalueWord,
7199}
7200
7201/// CREATE SEQUENCE statement
7202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7203#[cfg_attr(feature = "bindings", derive(TS))]
7204pub struct CreateSequence {
7205    pub name: TableRef,
7206    pub if_not_exists: bool,
7207    pub temporary: bool,
7208    #[serde(default)]
7209    pub or_replace: bool,
7210    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7211    #[serde(default, skip_serializing_if = "Option::is_none")]
7212    pub as_type: Option<DataType>,
7213    pub increment: Option<i64>,
7214    pub minvalue: Option<SequenceBound>,
7215    pub maxvalue: Option<SequenceBound>,
7216    pub start: Option<i64>,
7217    pub cache: Option<i64>,
7218    pub cycle: bool,
7219    pub owned_by: Option<TableRef>,
7220    /// Whether OWNED BY NONE was specified
7221    #[serde(default)]
7222    pub owned_by_none: bool,
7223    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7224    #[serde(default)]
7225    pub order: Option<bool>,
7226    /// Snowflake: COMMENT = 'value'
7227    #[serde(default)]
7228    pub comment: Option<String>,
7229    /// SHARING=<value> (Oracle)
7230    #[serde(default, skip_serializing_if = "Option::is_none")]
7231    pub sharing: Option<String>,
7232    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7233    #[serde(default, skip_serializing_if = "Option::is_none")]
7234    pub scale_modifier: Option<String>,
7235    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7236    #[serde(default, skip_serializing_if = "Option::is_none")]
7237    pub shard_modifier: Option<String>,
7238    /// Tracks the order in which properties appeared in the source
7239    #[serde(default)]
7240    pub property_order: Vec<SeqPropKind>,
7241}
7242
7243/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7245#[cfg_attr(feature = "bindings", derive(TS))]
7246pub enum SequenceBound {
7247    Value(i64),
7248    None,
7249}
7250
7251impl CreateSequence {
7252    pub fn new(name: impl Into<String>) -> Self {
7253        Self {
7254            name: TableRef::new(name),
7255            if_not_exists: false,
7256            temporary: false,
7257            or_replace: false,
7258            as_type: None,
7259            increment: None,
7260            minvalue: None,
7261            maxvalue: None,
7262            start: None,
7263            cache: None,
7264            cycle: false,
7265            owned_by: None,
7266            owned_by_none: false,
7267            order: None,
7268            comment: None,
7269            sharing: None,
7270            scale_modifier: None,
7271            shard_modifier: None,
7272            property_order: Vec::new(),
7273        }
7274    }
7275}
7276
7277/// DROP SEQUENCE statement
7278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7279#[cfg_attr(feature = "bindings", derive(TS))]
7280pub struct DropSequence {
7281    pub name: TableRef,
7282    pub if_exists: bool,
7283    pub cascade: bool,
7284}
7285
7286impl DropSequence {
7287    pub fn new(name: impl Into<String>) -> Self {
7288        Self {
7289            name: TableRef::new(name),
7290            if_exists: false,
7291            cascade: false,
7292        }
7293    }
7294}
7295
7296/// ALTER SEQUENCE statement
7297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7298#[cfg_attr(feature = "bindings", derive(TS))]
7299pub struct AlterSequence {
7300    pub name: TableRef,
7301    pub if_exists: bool,
7302    pub increment: Option<i64>,
7303    pub minvalue: Option<SequenceBound>,
7304    pub maxvalue: Option<SequenceBound>,
7305    pub start: Option<i64>,
7306    pub restart: Option<Option<i64>>,
7307    pub cache: Option<i64>,
7308    pub cycle: Option<bool>,
7309    pub owned_by: Option<Option<TableRef>>,
7310}
7311
7312impl AlterSequence {
7313    pub fn new(name: impl Into<String>) -> Self {
7314        Self {
7315            name: TableRef::new(name),
7316            if_exists: false,
7317            increment: None,
7318            minvalue: None,
7319            maxvalue: None,
7320            start: None,
7321            restart: None,
7322            cache: None,
7323            cycle: None,
7324            owned_by: None,
7325        }
7326    }
7327}
7328
7329/// CREATE TRIGGER statement
7330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7331#[cfg_attr(feature = "bindings", derive(TS))]
7332pub struct CreateTrigger {
7333    pub name: Identifier,
7334    pub table: TableRef,
7335    pub timing: TriggerTiming,
7336    pub events: Vec<TriggerEvent>,
7337    pub for_each: TriggerForEach,
7338    pub when: Option<Expression>,
7339    pub body: TriggerBody,
7340    pub or_replace: bool,
7341    pub constraint: bool,
7342    pub deferrable: Option<bool>,
7343    pub initially_deferred: Option<bool>,
7344    pub referencing: Option<TriggerReferencing>,
7345}
7346
7347/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7348#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7349#[cfg_attr(feature = "bindings", derive(TS))]
7350pub enum TriggerTiming {
7351    Before,
7352    After,
7353    InsteadOf,
7354}
7355
7356/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7358#[cfg_attr(feature = "bindings", derive(TS))]
7359pub enum TriggerEvent {
7360    Insert,
7361    Update(Option<Vec<Identifier>>),
7362    Delete,
7363    Truncate,
7364}
7365
7366/// Trigger FOR EACH clause
7367#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7368#[cfg_attr(feature = "bindings", derive(TS))]
7369pub enum TriggerForEach {
7370    Row,
7371    Statement,
7372}
7373
7374/// Trigger body
7375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7376#[cfg_attr(feature = "bindings", derive(TS))]
7377pub enum TriggerBody {
7378    /// EXECUTE FUNCTION/PROCEDURE name(args)
7379    Execute {
7380        function: TableRef,
7381        args: Vec<Expression>,
7382    },
7383    /// BEGIN ... END block
7384    Block(String),
7385}
7386
7387/// Trigger REFERENCING clause
7388#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7389#[cfg_attr(feature = "bindings", derive(TS))]
7390pub struct TriggerReferencing {
7391    pub old_table: Option<Identifier>,
7392    pub new_table: Option<Identifier>,
7393    pub old_row: Option<Identifier>,
7394    pub new_row: Option<Identifier>,
7395}
7396
7397impl CreateTrigger {
7398    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7399        Self {
7400            name: Identifier::new(name),
7401            table: TableRef::new(table),
7402            timing: TriggerTiming::Before,
7403            events: Vec::new(),
7404            for_each: TriggerForEach::Row,
7405            when: None,
7406            body: TriggerBody::Execute {
7407                function: TableRef::new(""),
7408                args: Vec::new(),
7409            },
7410            or_replace: false,
7411            constraint: false,
7412            deferrable: None,
7413            initially_deferred: None,
7414            referencing: None,
7415        }
7416    }
7417}
7418
7419/// DROP TRIGGER statement
7420#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7421#[cfg_attr(feature = "bindings", derive(TS))]
7422pub struct DropTrigger {
7423    pub name: Identifier,
7424    pub table: Option<TableRef>,
7425    pub if_exists: bool,
7426    pub cascade: bool,
7427}
7428
7429impl DropTrigger {
7430    pub fn new(name: impl Into<String>) -> Self {
7431        Self {
7432            name: Identifier::new(name),
7433            table: None,
7434            if_exists: false,
7435            cascade: false,
7436        }
7437    }
7438}
7439
7440/// CREATE TYPE statement
7441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7442#[cfg_attr(feature = "bindings", derive(TS))]
7443pub struct CreateType {
7444    pub name: TableRef,
7445    pub definition: TypeDefinition,
7446    pub if_not_exists: bool,
7447}
7448
7449/// Type definition
7450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7451#[cfg_attr(feature = "bindings", derive(TS))]
7452pub enum TypeDefinition {
7453    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7454    Enum(Vec<String>),
7455    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7456    Composite(Vec<TypeAttribute>),
7457    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7458    Range {
7459        subtype: DataType,
7460        subtype_diff: Option<String>,
7461        canonical: Option<String>,
7462    },
7463    /// Base type (for advanced usage)
7464    Base {
7465        input: String,
7466        output: String,
7467        internallength: Option<i32>,
7468    },
7469    /// Domain type
7470    Domain {
7471        base_type: DataType,
7472        default: Option<Expression>,
7473        constraints: Vec<DomainConstraint>,
7474    },
7475}
7476
7477/// Type attribute for composite types
7478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7479#[cfg_attr(feature = "bindings", derive(TS))]
7480pub struct TypeAttribute {
7481    pub name: Identifier,
7482    pub data_type: DataType,
7483    pub collate: Option<Identifier>,
7484}
7485
7486/// Domain constraint
7487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7488#[cfg_attr(feature = "bindings", derive(TS))]
7489pub struct DomainConstraint {
7490    pub name: Option<Identifier>,
7491    pub check: Expression,
7492}
7493
7494impl CreateType {
7495    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7496        Self {
7497            name: TableRef::new(name),
7498            definition: TypeDefinition::Enum(values),
7499            if_not_exists: false,
7500        }
7501    }
7502
7503    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
7504        Self {
7505            name: TableRef::new(name),
7506            definition: TypeDefinition::Composite(attributes),
7507            if_not_exists: false,
7508        }
7509    }
7510}
7511
7512/// DROP TYPE statement
7513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7514#[cfg_attr(feature = "bindings", derive(TS))]
7515pub struct DropType {
7516    pub name: TableRef,
7517    pub if_exists: bool,
7518    pub cascade: bool,
7519}
7520
7521impl DropType {
7522    pub fn new(name: impl Into<String>) -> Self {
7523        Self {
7524            name: TableRef::new(name),
7525            if_exists: false,
7526            cascade: false,
7527        }
7528    }
7529}
7530
7531/// DESCRIBE statement - shows table structure or query plan
7532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7533#[cfg_attr(feature = "bindings", derive(TS))]
7534pub struct Describe {
7535    /// The target to describe (table name or query)
7536    pub target: Expression,
7537    /// EXTENDED format
7538    pub extended: bool,
7539    /// FORMATTED format
7540    pub formatted: bool,
7541    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
7542    #[serde(default)]
7543    pub kind: Option<String>,
7544    /// Properties like type=stage
7545    #[serde(default)]
7546    pub properties: Vec<(String, String)>,
7547    /// Style keyword (e.g., "ANALYZE", "HISTORY")
7548    #[serde(default, skip_serializing_if = "Option::is_none")]
7549    pub style: Option<String>,
7550    /// Partition specification for DESCRIBE PARTITION
7551    #[serde(default)]
7552    pub partition: Option<Box<Expression>>,
7553    /// Leading comments before the statement
7554    #[serde(default)]
7555    pub leading_comments: Vec<String>,
7556    /// AS JSON suffix (Databricks)
7557    #[serde(default)]
7558    pub as_json: bool,
7559}
7560
7561impl Describe {
7562    pub fn new(target: Expression) -> Self {
7563        Self {
7564            target,
7565            extended: false,
7566            formatted: false,
7567            kind: None,
7568            properties: Vec::new(),
7569            style: None,
7570            partition: None,
7571            leading_comments: Vec::new(),
7572            as_json: false,
7573        }
7574    }
7575}
7576
7577/// SHOW statement - displays database objects
7578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7579#[cfg_attr(feature = "bindings", derive(TS))]
7580pub struct Show {
7581    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
7582    pub this: String,
7583    /// Whether TERSE was specified
7584    #[serde(default)]
7585    pub terse: bool,
7586    /// Whether HISTORY was specified
7587    #[serde(default)]
7588    pub history: bool,
7589    /// LIKE pattern
7590    pub like: Option<Expression>,
7591    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
7592    pub scope_kind: Option<String>,
7593    /// IN scope object
7594    pub scope: Option<Expression>,
7595    /// STARTS WITH pattern
7596    pub starts_with: Option<Expression>,
7597    /// LIMIT clause
7598    pub limit: Option<Box<Limit>>,
7599    /// FROM clause (for specific object)
7600    pub from: Option<Expression>,
7601    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
7602    #[serde(default, skip_serializing_if = "Option::is_none")]
7603    pub where_clause: Option<Expression>,
7604    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
7605    #[serde(default, skip_serializing_if = "Option::is_none")]
7606    pub for_target: Option<Expression>,
7607    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
7608    #[serde(default, skip_serializing_if = "Option::is_none")]
7609    pub db: Option<Expression>,
7610    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
7611    #[serde(default, skip_serializing_if = "Option::is_none")]
7612    pub target: Option<Expression>,
7613    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
7614    #[serde(default, skip_serializing_if = "Option::is_none")]
7615    pub mutex: Option<bool>,
7616    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
7617    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7618    pub privileges: Vec<String>,
7619}
7620
7621impl Show {
7622    pub fn new(this: impl Into<String>) -> Self {
7623        Self {
7624            this: this.into(),
7625            terse: false,
7626            history: false,
7627            like: None,
7628            scope_kind: None,
7629            scope: None,
7630            starts_with: None,
7631            limit: None,
7632            from: None,
7633            where_clause: None,
7634            for_target: None,
7635            db: None,
7636            target: None,
7637            mutex: None,
7638            privileges: Vec::new(),
7639        }
7640    }
7641}
7642
7643/// Represent an explicit parenthesized expression for grouping precedence.
7644///
7645/// Preserves user-written parentheses so that `(a + b) * c` round-trips
7646/// correctly instead of being flattened to `a + b * c`.
7647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7648#[cfg_attr(feature = "bindings", derive(TS))]
7649pub struct Paren {
7650    /// The inner expression wrapped by parentheses.
7651    pub this: Expression,
7652    #[serde(default)]
7653    pub trailing_comments: Vec<String>,
7654}
7655
7656/// Expression annotated with trailing comments (for round-trip preservation)
7657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7658#[cfg_attr(feature = "bindings", derive(TS))]
7659pub struct Annotated {
7660    pub this: Expression,
7661    pub trailing_comments: Vec<String>,
7662}
7663
7664// === BATCH GENERATED STRUCT DEFINITIONS ===
7665// Generated from Python sqlglot expressions.py
7666
7667/// Refresh
7668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7669#[cfg_attr(feature = "bindings", derive(TS))]
7670pub struct Refresh {
7671    pub this: Box<Expression>,
7672    pub kind: String,
7673}
7674
7675/// LockingStatement
7676#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7677#[cfg_attr(feature = "bindings", derive(TS))]
7678pub struct LockingStatement {
7679    pub this: Box<Expression>,
7680    pub expression: Box<Expression>,
7681}
7682
7683/// SequenceProperties
7684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7685#[cfg_attr(feature = "bindings", derive(TS))]
7686pub struct SequenceProperties {
7687    #[serde(default)]
7688    pub increment: Option<Box<Expression>>,
7689    #[serde(default)]
7690    pub minvalue: Option<Box<Expression>>,
7691    #[serde(default)]
7692    pub maxvalue: Option<Box<Expression>>,
7693    #[serde(default)]
7694    pub cache: Option<Box<Expression>>,
7695    #[serde(default)]
7696    pub start: Option<Box<Expression>>,
7697    #[serde(default)]
7698    pub owned: Option<Box<Expression>>,
7699    #[serde(default)]
7700    pub options: Vec<Expression>,
7701}
7702
7703/// TruncateTable
7704#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7705#[cfg_attr(feature = "bindings", derive(TS))]
7706pub struct TruncateTable {
7707    #[serde(default)]
7708    pub expressions: Vec<Expression>,
7709    #[serde(default)]
7710    pub is_database: Option<Box<Expression>>,
7711    #[serde(default)]
7712    pub exists: bool,
7713    #[serde(default)]
7714    pub only: Option<Box<Expression>>,
7715    #[serde(default)]
7716    pub cluster: Option<Box<Expression>>,
7717    #[serde(default)]
7718    pub identity: Option<Box<Expression>>,
7719    #[serde(default)]
7720    pub option: Option<Box<Expression>>,
7721    #[serde(default)]
7722    pub partition: Option<Box<Expression>>,
7723}
7724
7725/// Clone
7726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7727#[cfg_attr(feature = "bindings", derive(TS))]
7728pub struct Clone {
7729    pub this: Box<Expression>,
7730    #[serde(default)]
7731    pub shallow: Option<Box<Expression>>,
7732    #[serde(default)]
7733    pub copy: Option<Box<Expression>>,
7734}
7735
7736/// Attach
7737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7738#[cfg_attr(feature = "bindings", derive(TS))]
7739pub struct Attach {
7740    pub this: Box<Expression>,
7741    #[serde(default)]
7742    pub exists: bool,
7743    #[serde(default)]
7744    pub expressions: Vec<Expression>,
7745}
7746
7747/// Detach
7748#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7749#[cfg_attr(feature = "bindings", derive(TS))]
7750pub struct Detach {
7751    pub this: Box<Expression>,
7752    #[serde(default)]
7753    pub exists: bool,
7754}
7755
7756/// Install
7757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7758#[cfg_attr(feature = "bindings", derive(TS))]
7759pub struct Install {
7760    pub this: Box<Expression>,
7761    #[serde(default)]
7762    pub from_: Option<Box<Expression>>,
7763    #[serde(default)]
7764    pub force: Option<Box<Expression>>,
7765}
7766
7767/// Summarize
7768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7769#[cfg_attr(feature = "bindings", derive(TS))]
7770pub struct Summarize {
7771    pub this: Box<Expression>,
7772    #[serde(default)]
7773    pub table: Option<Box<Expression>>,
7774}
7775
7776/// Declare
7777#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7778#[cfg_attr(feature = "bindings", derive(TS))]
7779pub struct Declare {
7780    #[serde(default)]
7781    pub expressions: Vec<Expression>,
7782}
7783
7784/// DeclareItem
7785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7786#[cfg_attr(feature = "bindings", derive(TS))]
7787pub struct DeclareItem {
7788    pub this: Box<Expression>,
7789    #[serde(default)]
7790    pub kind: Option<String>,
7791    #[serde(default)]
7792    pub default: Option<Box<Expression>>,
7793    #[serde(default)]
7794    pub has_as: bool,
7795    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
7796    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7797    pub additional_names: Vec<Expression>,
7798}
7799
7800/// Set
7801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7802#[cfg_attr(feature = "bindings", derive(TS))]
7803pub struct Set {
7804    #[serde(default)]
7805    pub expressions: Vec<Expression>,
7806    #[serde(default)]
7807    pub unset: Option<Box<Expression>>,
7808    #[serde(default)]
7809    pub tag: Option<Box<Expression>>,
7810}
7811
7812/// Heredoc
7813#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7814#[cfg_attr(feature = "bindings", derive(TS))]
7815pub struct Heredoc {
7816    pub this: Box<Expression>,
7817    #[serde(default)]
7818    pub tag: Option<Box<Expression>>,
7819}
7820
7821/// QueryBand
7822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7823#[cfg_attr(feature = "bindings", derive(TS))]
7824pub struct QueryBand {
7825    pub this: Box<Expression>,
7826    #[serde(default)]
7827    pub scope: Option<Box<Expression>>,
7828    #[serde(default)]
7829    pub update: Option<Box<Expression>>,
7830}
7831
7832/// UserDefinedFunction
7833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7834#[cfg_attr(feature = "bindings", derive(TS))]
7835pub struct UserDefinedFunction {
7836    pub this: Box<Expression>,
7837    #[serde(default)]
7838    pub expressions: Vec<Expression>,
7839    #[serde(default)]
7840    pub wrapped: Option<Box<Expression>>,
7841}
7842
7843/// RecursiveWithSearch
7844#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7845#[cfg_attr(feature = "bindings", derive(TS))]
7846pub struct RecursiveWithSearch {
7847    pub kind: String,
7848    pub this: Box<Expression>,
7849    pub expression: Box<Expression>,
7850    #[serde(default)]
7851    pub using: Option<Box<Expression>>,
7852}
7853
7854/// ProjectionDef
7855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7856#[cfg_attr(feature = "bindings", derive(TS))]
7857pub struct ProjectionDef {
7858    pub this: Box<Expression>,
7859    pub expression: Box<Expression>,
7860}
7861
7862/// TableAlias
7863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7864#[cfg_attr(feature = "bindings", derive(TS))]
7865pub struct TableAlias {
7866    #[serde(default)]
7867    pub this: Option<Box<Expression>>,
7868    #[serde(default)]
7869    pub columns: Vec<Expression>,
7870}
7871
7872/// ByteString
7873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7874#[cfg_attr(feature = "bindings", derive(TS))]
7875pub struct ByteString {
7876    pub this: Box<Expression>,
7877    #[serde(default)]
7878    pub is_bytes: Option<Box<Expression>>,
7879}
7880
7881/// HexStringExpr - Hex string expression (not literal)
7882/// BigQuery: converts to FROM_HEX(this)
7883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7884#[cfg_attr(feature = "bindings", derive(TS))]
7885pub struct HexStringExpr {
7886    pub this: Box<Expression>,
7887    #[serde(default)]
7888    pub is_integer: Option<bool>,
7889}
7890
7891/// UnicodeString
7892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7893#[cfg_attr(feature = "bindings", derive(TS))]
7894pub struct UnicodeString {
7895    pub this: Box<Expression>,
7896    #[serde(default)]
7897    pub escape: Option<Box<Expression>>,
7898}
7899
7900/// AlterColumn
7901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7902#[cfg_attr(feature = "bindings", derive(TS))]
7903pub struct AlterColumn {
7904    pub this: Box<Expression>,
7905    #[serde(default)]
7906    pub dtype: Option<Box<Expression>>,
7907    #[serde(default)]
7908    pub collate: Option<Box<Expression>>,
7909    #[serde(default)]
7910    pub using: Option<Box<Expression>>,
7911    #[serde(default)]
7912    pub default: Option<Box<Expression>>,
7913    #[serde(default)]
7914    pub drop: Option<Box<Expression>>,
7915    #[serde(default)]
7916    pub comment: Option<Box<Expression>>,
7917    #[serde(default)]
7918    pub allow_null: Option<Box<Expression>>,
7919    #[serde(default)]
7920    pub visible: Option<Box<Expression>>,
7921    #[serde(default)]
7922    pub rename_to: Option<Box<Expression>>,
7923}
7924
7925/// AlterSortKey
7926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7927#[cfg_attr(feature = "bindings", derive(TS))]
7928pub struct AlterSortKey {
7929    #[serde(default)]
7930    pub this: Option<Box<Expression>>,
7931    #[serde(default)]
7932    pub expressions: Vec<Expression>,
7933    #[serde(default)]
7934    pub compound: Option<Box<Expression>>,
7935}
7936
7937/// AlterSet
7938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7939#[cfg_attr(feature = "bindings", derive(TS))]
7940pub struct AlterSet {
7941    #[serde(default)]
7942    pub expressions: Vec<Expression>,
7943    #[serde(default)]
7944    pub option: Option<Box<Expression>>,
7945    #[serde(default)]
7946    pub tablespace: Option<Box<Expression>>,
7947    #[serde(default)]
7948    pub access_method: Option<Box<Expression>>,
7949    #[serde(default)]
7950    pub file_format: Option<Box<Expression>>,
7951    #[serde(default)]
7952    pub copy_options: Option<Box<Expression>>,
7953    #[serde(default)]
7954    pub tag: Option<Box<Expression>>,
7955    #[serde(default)]
7956    pub location: Option<Box<Expression>>,
7957    #[serde(default)]
7958    pub serde: Option<Box<Expression>>,
7959}
7960
7961/// RenameColumn
7962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7963#[cfg_attr(feature = "bindings", derive(TS))]
7964pub struct RenameColumn {
7965    pub this: Box<Expression>,
7966    #[serde(default)]
7967    pub to: Option<Box<Expression>>,
7968    #[serde(default)]
7969    pub exists: bool,
7970}
7971
7972/// Comprehension
7973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7974#[cfg_attr(feature = "bindings", derive(TS))]
7975pub struct Comprehension {
7976    pub this: Box<Expression>,
7977    pub expression: Box<Expression>,
7978    #[serde(default)]
7979    pub position: Option<Box<Expression>>,
7980    #[serde(default)]
7981    pub iterator: Option<Box<Expression>>,
7982    #[serde(default)]
7983    pub condition: Option<Box<Expression>>,
7984}
7985
7986/// MergeTreeTTLAction
7987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7988#[cfg_attr(feature = "bindings", derive(TS))]
7989pub struct MergeTreeTTLAction {
7990    pub this: Box<Expression>,
7991    #[serde(default)]
7992    pub delete: Option<Box<Expression>>,
7993    #[serde(default)]
7994    pub recompress: Option<Box<Expression>>,
7995    #[serde(default)]
7996    pub to_disk: Option<Box<Expression>>,
7997    #[serde(default)]
7998    pub to_volume: Option<Box<Expression>>,
7999}
8000
8001/// MergeTreeTTL
8002#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8003#[cfg_attr(feature = "bindings", derive(TS))]
8004pub struct MergeTreeTTL {
8005    #[serde(default)]
8006    pub expressions: Vec<Expression>,
8007    #[serde(default)]
8008    pub where_: Option<Box<Expression>>,
8009    #[serde(default)]
8010    pub group: Option<Box<Expression>>,
8011    #[serde(default)]
8012    pub aggregates: Option<Box<Expression>>,
8013}
8014
8015/// IndexConstraintOption
8016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8017#[cfg_attr(feature = "bindings", derive(TS))]
8018pub struct IndexConstraintOption {
8019    #[serde(default)]
8020    pub key_block_size: Option<Box<Expression>>,
8021    #[serde(default)]
8022    pub using: Option<Box<Expression>>,
8023    #[serde(default)]
8024    pub parser: Option<Box<Expression>>,
8025    #[serde(default)]
8026    pub comment: Option<Box<Expression>>,
8027    #[serde(default)]
8028    pub visible: Option<Box<Expression>>,
8029    #[serde(default)]
8030    pub engine_attr: Option<Box<Expression>>,
8031    #[serde(default)]
8032    pub secondary_engine_attr: Option<Box<Expression>>,
8033}
8034
8035/// PeriodForSystemTimeConstraint
8036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8037#[cfg_attr(feature = "bindings", derive(TS))]
8038pub struct PeriodForSystemTimeConstraint {
8039    pub this: Box<Expression>,
8040    pub expression: Box<Expression>,
8041}
8042
8043/// CaseSpecificColumnConstraint
8044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8045#[cfg_attr(feature = "bindings", derive(TS))]
8046pub struct CaseSpecificColumnConstraint {
8047    #[serde(default)]
8048    pub not_: Option<Box<Expression>>,
8049}
8050
8051/// CharacterSetColumnConstraint
8052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8053#[cfg_attr(feature = "bindings", derive(TS))]
8054pub struct CharacterSetColumnConstraint {
8055    pub this: Box<Expression>,
8056}
8057
8058/// CheckColumnConstraint
8059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8060#[cfg_attr(feature = "bindings", derive(TS))]
8061pub struct CheckColumnConstraint {
8062    pub this: Box<Expression>,
8063    #[serde(default)]
8064    pub enforced: Option<Box<Expression>>,
8065}
8066
8067/// CompressColumnConstraint
8068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8069#[cfg_attr(feature = "bindings", derive(TS))]
8070pub struct CompressColumnConstraint {
8071    #[serde(default)]
8072    pub this: Option<Box<Expression>>,
8073}
8074
8075/// DateFormatColumnConstraint
8076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8077#[cfg_attr(feature = "bindings", derive(TS))]
8078pub struct DateFormatColumnConstraint {
8079    pub this: Box<Expression>,
8080}
8081
8082/// EphemeralColumnConstraint
8083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8084#[cfg_attr(feature = "bindings", derive(TS))]
8085pub struct EphemeralColumnConstraint {
8086    #[serde(default)]
8087    pub this: Option<Box<Expression>>,
8088}
8089
8090/// WithOperator
8091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8092#[cfg_attr(feature = "bindings", derive(TS))]
8093pub struct WithOperator {
8094    pub this: Box<Expression>,
8095    pub op: String,
8096}
8097
8098/// GeneratedAsIdentityColumnConstraint
8099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8100#[cfg_attr(feature = "bindings", derive(TS))]
8101pub struct GeneratedAsIdentityColumnConstraint {
8102    #[serde(default)]
8103    pub this: Option<Box<Expression>>,
8104    #[serde(default)]
8105    pub expression: Option<Box<Expression>>,
8106    #[serde(default)]
8107    pub on_null: Option<Box<Expression>>,
8108    #[serde(default)]
8109    pub start: Option<Box<Expression>>,
8110    #[serde(default)]
8111    pub increment: Option<Box<Expression>>,
8112    #[serde(default)]
8113    pub minvalue: Option<Box<Expression>>,
8114    #[serde(default)]
8115    pub maxvalue: Option<Box<Expression>>,
8116    #[serde(default)]
8117    pub cycle: Option<Box<Expression>>,
8118    #[serde(default)]
8119    pub order: Option<Box<Expression>>,
8120}
8121
8122/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8123/// TSQL: outputs "IDENTITY"
8124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8125#[cfg_attr(feature = "bindings", derive(TS))]
8126pub struct AutoIncrementColumnConstraint;
8127
8128/// CommentColumnConstraint - Column comment marker
8129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8130#[cfg_attr(feature = "bindings", derive(TS))]
8131pub struct CommentColumnConstraint;
8132
8133/// GeneratedAsRowColumnConstraint
8134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8135#[cfg_attr(feature = "bindings", derive(TS))]
8136pub struct GeneratedAsRowColumnConstraint {
8137    #[serde(default)]
8138    pub start: Option<Box<Expression>>,
8139    #[serde(default)]
8140    pub hidden: Option<Box<Expression>>,
8141}
8142
8143/// IndexColumnConstraint
8144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8145#[cfg_attr(feature = "bindings", derive(TS))]
8146pub struct IndexColumnConstraint {
8147    #[serde(default)]
8148    pub this: Option<Box<Expression>>,
8149    #[serde(default)]
8150    pub expressions: Vec<Expression>,
8151    #[serde(default)]
8152    pub kind: Option<String>,
8153    #[serde(default)]
8154    pub index_type: Option<Box<Expression>>,
8155    #[serde(default)]
8156    pub options: Vec<Expression>,
8157    #[serde(default)]
8158    pub expression: Option<Box<Expression>>,
8159    #[serde(default)]
8160    pub granularity: Option<Box<Expression>>,
8161}
8162
8163/// MaskingPolicyColumnConstraint
8164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8165#[cfg_attr(feature = "bindings", derive(TS))]
8166pub struct MaskingPolicyColumnConstraint {
8167    pub this: Box<Expression>,
8168    #[serde(default)]
8169    pub expressions: Vec<Expression>,
8170}
8171
8172/// NotNullColumnConstraint
8173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8174#[cfg_attr(feature = "bindings", derive(TS))]
8175pub struct NotNullColumnConstraint {
8176    #[serde(default)]
8177    pub allow_null: Option<Box<Expression>>,
8178}
8179
8180/// DefaultColumnConstraint - DEFAULT value for a column
8181#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8182#[cfg_attr(feature = "bindings", derive(TS))]
8183pub struct DefaultColumnConstraint {
8184    pub this: Box<Expression>,
8185}
8186
8187/// PrimaryKeyColumnConstraint
8188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8189#[cfg_attr(feature = "bindings", derive(TS))]
8190pub struct PrimaryKeyColumnConstraint {
8191    #[serde(default)]
8192    pub desc: Option<Box<Expression>>,
8193    #[serde(default)]
8194    pub options: Vec<Expression>,
8195}
8196
8197/// UniqueColumnConstraint
8198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8199#[cfg_attr(feature = "bindings", derive(TS))]
8200pub struct UniqueColumnConstraint {
8201    #[serde(default)]
8202    pub this: Option<Box<Expression>>,
8203    #[serde(default)]
8204    pub index_type: Option<Box<Expression>>,
8205    #[serde(default)]
8206    pub on_conflict: Option<Box<Expression>>,
8207    #[serde(default)]
8208    pub nulls: Option<Box<Expression>>,
8209    #[serde(default)]
8210    pub options: Vec<Expression>,
8211}
8212
8213/// WatermarkColumnConstraint
8214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8215#[cfg_attr(feature = "bindings", derive(TS))]
8216pub struct WatermarkColumnConstraint {
8217    pub this: Box<Expression>,
8218    pub expression: Box<Expression>,
8219}
8220
8221/// ComputedColumnConstraint
8222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8223#[cfg_attr(feature = "bindings", derive(TS))]
8224pub struct ComputedColumnConstraint {
8225    pub this: Box<Expression>,
8226    #[serde(default)]
8227    pub persisted: Option<Box<Expression>>,
8228    #[serde(default)]
8229    pub not_null: Option<Box<Expression>>,
8230    #[serde(default)]
8231    pub data_type: Option<Box<Expression>>,
8232}
8233
8234/// InOutColumnConstraint
8235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8236#[cfg_attr(feature = "bindings", derive(TS))]
8237pub struct InOutColumnConstraint {
8238    #[serde(default)]
8239    pub input_: Option<Box<Expression>>,
8240    #[serde(default)]
8241    pub output: Option<Box<Expression>>,
8242}
8243
8244/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8246#[cfg_attr(feature = "bindings", derive(TS))]
8247pub struct PathColumnConstraint {
8248    pub this: Box<Expression>,
8249}
8250
8251/// Constraint
8252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8253#[cfg_attr(feature = "bindings", derive(TS))]
8254pub struct Constraint {
8255    pub this: Box<Expression>,
8256    #[serde(default)]
8257    pub expressions: Vec<Expression>,
8258}
8259
8260/// Export
8261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8262#[cfg_attr(feature = "bindings", derive(TS))]
8263pub struct Export {
8264    pub this: Box<Expression>,
8265    #[serde(default)]
8266    pub connection: Option<Box<Expression>>,
8267    #[serde(default)]
8268    pub options: Vec<Expression>,
8269}
8270
8271/// Filter
8272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8273#[cfg_attr(feature = "bindings", derive(TS))]
8274pub struct Filter {
8275    pub this: Box<Expression>,
8276    pub expression: Box<Expression>,
8277}
8278
8279/// Changes
8280#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8281#[cfg_attr(feature = "bindings", derive(TS))]
8282pub struct Changes {
8283    #[serde(default)]
8284    pub information: Option<Box<Expression>>,
8285    #[serde(default)]
8286    pub at_before: Option<Box<Expression>>,
8287    #[serde(default)]
8288    pub end: Option<Box<Expression>>,
8289}
8290
8291/// Directory
8292#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8293#[cfg_attr(feature = "bindings", derive(TS))]
8294pub struct Directory {
8295    pub this: Box<Expression>,
8296    #[serde(default)]
8297    pub local: Option<Box<Expression>>,
8298    #[serde(default)]
8299    pub row_format: Option<Box<Expression>>,
8300}
8301
8302/// ForeignKey
8303#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8304#[cfg_attr(feature = "bindings", derive(TS))]
8305pub struct ForeignKey {
8306    #[serde(default)]
8307    pub expressions: Vec<Expression>,
8308    #[serde(default)]
8309    pub reference: Option<Box<Expression>>,
8310    #[serde(default)]
8311    pub delete: Option<Box<Expression>>,
8312    #[serde(default)]
8313    pub update: Option<Box<Expression>>,
8314    #[serde(default)]
8315    pub options: Vec<Expression>,
8316}
8317
8318/// ColumnPrefix
8319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8320#[cfg_attr(feature = "bindings", derive(TS))]
8321pub struct ColumnPrefix {
8322    pub this: Box<Expression>,
8323    pub expression: Box<Expression>,
8324}
8325
8326/// PrimaryKey
8327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8328#[cfg_attr(feature = "bindings", derive(TS))]
8329pub struct PrimaryKey {
8330    #[serde(default)]
8331    pub this: Option<Box<Expression>>,
8332    #[serde(default)]
8333    pub expressions: Vec<Expression>,
8334    #[serde(default)]
8335    pub options: Vec<Expression>,
8336    #[serde(default)]
8337    pub include: Option<Box<Expression>>,
8338}
8339
8340/// Into
8341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8342#[cfg_attr(feature = "bindings", derive(TS))]
8343pub struct IntoClause {
8344    #[serde(default)]
8345    pub this: Option<Box<Expression>>,
8346    #[serde(default)]
8347    pub temporary: bool,
8348    #[serde(default)]
8349    pub unlogged: Option<Box<Expression>>,
8350    #[serde(default)]
8351    pub bulk_collect: Option<Box<Expression>>,
8352    #[serde(default)]
8353    pub expressions: Vec<Expression>,
8354}
8355
8356/// JoinHint
8357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8358#[cfg_attr(feature = "bindings", derive(TS))]
8359pub struct JoinHint {
8360    pub this: Box<Expression>,
8361    #[serde(default)]
8362    pub expressions: Vec<Expression>,
8363}
8364
8365/// Opclass
8366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8367#[cfg_attr(feature = "bindings", derive(TS))]
8368pub struct Opclass {
8369    pub this: Box<Expression>,
8370    pub expression: Box<Expression>,
8371}
8372
8373/// Index
8374#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8375#[cfg_attr(feature = "bindings", derive(TS))]
8376pub struct Index {
8377    #[serde(default)]
8378    pub this: Option<Box<Expression>>,
8379    #[serde(default)]
8380    pub table: Option<Box<Expression>>,
8381    #[serde(default)]
8382    pub unique: bool,
8383    #[serde(default)]
8384    pub primary: Option<Box<Expression>>,
8385    #[serde(default)]
8386    pub amp: Option<Box<Expression>>,
8387    #[serde(default)]
8388    pub params: Vec<Expression>,
8389}
8390
8391/// IndexParameters
8392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8393#[cfg_attr(feature = "bindings", derive(TS))]
8394pub struct IndexParameters {
8395    #[serde(default)]
8396    pub using: Option<Box<Expression>>,
8397    #[serde(default)]
8398    pub include: Option<Box<Expression>>,
8399    #[serde(default)]
8400    pub columns: Vec<Expression>,
8401    #[serde(default)]
8402    pub with_storage: Option<Box<Expression>>,
8403    #[serde(default)]
8404    pub partition_by: Option<Box<Expression>>,
8405    #[serde(default)]
8406    pub tablespace: Option<Box<Expression>>,
8407    #[serde(default)]
8408    pub where_: Option<Box<Expression>>,
8409    #[serde(default)]
8410    pub on: Option<Box<Expression>>,
8411}
8412
8413/// ConditionalInsert
8414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8415#[cfg_attr(feature = "bindings", derive(TS))]
8416pub struct ConditionalInsert {
8417    pub this: Box<Expression>,
8418    #[serde(default)]
8419    pub expression: Option<Box<Expression>>,
8420    #[serde(default)]
8421    pub else_: Option<Box<Expression>>,
8422}
8423
8424/// MultitableInserts
8425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8426#[cfg_attr(feature = "bindings", derive(TS))]
8427pub struct MultitableInserts {
8428    #[serde(default)]
8429    pub expressions: Vec<Expression>,
8430    pub kind: String,
8431    #[serde(default)]
8432    pub source: Option<Box<Expression>>,
8433    /// Leading comments before the statement
8434    #[serde(default)]
8435    pub leading_comments: Vec<String>,
8436}
8437
8438/// OnConflict
8439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8440#[cfg_attr(feature = "bindings", derive(TS))]
8441pub struct OnConflict {
8442    #[serde(default)]
8443    pub duplicate: Option<Box<Expression>>,
8444    #[serde(default)]
8445    pub expressions: Vec<Expression>,
8446    #[serde(default)]
8447    pub action: Option<Box<Expression>>,
8448    #[serde(default)]
8449    pub conflict_keys: Option<Box<Expression>>,
8450    #[serde(default)]
8451    pub index_predicate: Option<Box<Expression>>,
8452    #[serde(default)]
8453    pub constraint: Option<Box<Expression>>,
8454    #[serde(default)]
8455    pub where_: Option<Box<Expression>>,
8456}
8457
8458/// OnCondition
8459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8460#[cfg_attr(feature = "bindings", derive(TS))]
8461pub struct OnCondition {
8462    #[serde(default)]
8463    pub error: Option<Box<Expression>>,
8464    #[serde(default)]
8465    pub empty: Option<Box<Expression>>,
8466    #[serde(default)]
8467    pub null: Option<Box<Expression>>,
8468}
8469
8470/// Returning
8471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8472#[cfg_attr(feature = "bindings", derive(TS))]
8473pub struct Returning {
8474    #[serde(default)]
8475    pub expressions: Vec<Expression>,
8476    #[serde(default)]
8477    pub into: Option<Box<Expression>>,
8478}
8479
8480/// Introducer
8481#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8482#[cfg_attr(feature = "bindings", derive(TS))]
8483pub struct Introducer {
8484    pub this: Box<Expression>,
8485    pub expression: Box<Expression>,
8486}
8487
8488/// PartitionRange
8489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8490#[cfg_attr(feature = "bindings", derive(TS))]
8491pub struct PartitionRange {
8492    pub this: Box<Expression>,
8493    #[serde(default)]
8494    pub expression: Option<Box<Expression>>,
8495    #[serde(default)]
8496    pub expressions: Vec<Expression>,
8497}
8498
8499/// Group
8500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8501#[cfg_attr(feature = "bindings", derive(TS))]
8502pub struct Group {
8503    #[serde(default)]
8504    pub expressions: Vec<Expression>,
8505    #[serde(default)]
8506    pub grouping_sets: Option<Box<Expression>>,
8507    #[serde(default)]
8508    pub cube: Option<Box<Expression>>,
8509    #[serde(default)]
8510    pub rollup: Option<Box<Expression>>,
8511    #[serde(default)]
8512    pub totals: Option<Box<Expression>>,
8513    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
8514    #[serde(default)]
8515    pub all: Option<bool>,
8516}
8517
8518/// Cube
8519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8520#[cfg_attr(feature = "bindings", derive(TS))]
8521pub struct Cube {
8522    #[serde(default)]
8523    pub expressions: Vec<Expression>,
8524}
8525
8526/// Rollup
8527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8528#[cfg_attr(feature = "bindings", derive(TS))]
8529pub struct Rollup {
8530    #[serde(default)]
8531    pub expressions: Vec<Expression>,
8532}
8533
8534/// GroupingSets
8535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8536#[cfg_attr(feature = "bindings", derive(TS))]
8537pub struct GroupingSets {
8538    #[serde(default)]
8539    pub expressions: Vec<Expression>,
8540}
8541
8542/// LimitOptions
8543#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8544#[cfg_attr(feature = "bindings", derive(TS))]
8545pub struct LimitOptions {
8546    #[serde(default)]
8547    pub percent: Option<Box<Expression>>,
8548    #[serde(default)]
8549    pub rows: Option<Box<Expression>>,
8550    #[serde(default)]
8551    pub with_ties: Option<Box<Expression>>,
8552}
8553
8554/// Lateral
8555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8556#[cfg_attr(feature = "bindings", derive(TS))]
8557pub struct Lateral {
8558    pub this: Box<Expression>,
8559    #[serde(default)]
8560    pub view: Option<Box<Expression>>,
8561    #[serde(default)]
8562    pub outer: Option<Box<Expression>>,
8563    #[serde(default)]
8564    pub alias: Option<String>,
8565    /// Whether the alias was originally quoted (backtick/double-quote)
8566    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8567    pub alias_quoted: bool,
8568    #[serde(default)]
8569    pub cross_apply: Option<Box<Expression>>,
8570    #[serde(default)]
8571    pub ordinality: Option<Box<Expression>>,
8572    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
8573    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8574    pub column_aliases: Vec<String>,
8575}
8576
8577/// TableFromRows
8578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8579#[cfg_attr(feature = "bindings", derive(TS))]
8580pub struct TableFromRows {
8581    pub this: Box<Expression>,
8582    #[serde(default)]
8583    pub alias: Option<String>,
8584    #[serde(default)]
8585    pub joins: Vec<Expression>,
8586    #[serde(default)]
8587    pub pivots: Option<Box<Expression>>,
8588    #[serde(default)]
8589    pub sample: Option<Box<Expression>>,
8590}
8591
8592/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
8593/// Used for set-returning functions with typed column definitions
8594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8595#[cfg_attr(feature = "bindings", derive(TS))]
8596pub struct RowsFrom {
8597    /// List of function expressions, each potentially with an alias and typed columns
8598    pub expressions: Vec<Expression>,
8599    /// WITH ORDINALITY modifier
8600    #[serde(default)]
8601    pub ordinality: bool,
8602    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
8603    #[serde(default)]
8604    pub alias: Option<Box<Expression>>,
8605}
8606
8607/// WithFill
8608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8609#[cfg_attr(feature = "bindings", derive(TS))]
8610pub struct WithFill {
8611    #[serde(default)]
8612    pub from_: Option<Box<Expression>>,
8613    #[serde(default)]
8614    pub to: Option<Box<Expression>>,
8615    #[serde(default)]
8616    pub step: Option<Box<Expression>>,
8617    #[serde(default)]
8618    pub staleness: Option<Box<Expression>>,
8619    #[serde(default)]
8620    pub interpolate: Option<Box<Expression>>,
8621}
8622
8623/// Property
8624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8625#[cfg_attr(feature = "bindings", derive(TS))]
8626pub struct Property {
8627    pub this: Box<Expression>,
8628    #[serde(default)]
8629    pub value: Option<Box<Expression>>,
8630}
8631
8632/// GrantPrivilege
8633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8634#[cfg_attr(feature = "bindings", derive(TS))]
8635pub struct GrantPrivilege {
8636    pub this: Box<Expression>,
8637    #[serde(default)]
8638    pub expressions: Vec<Expression>,
8639}
8640
8641/// AllowedValuesProperty
8642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8643#[cfg_attr(feature = "bindings", derive(TS))]
8644pub struct AllowedValuesProperty {
8645    #[serde(default)]
8646    pub expressions: Vec<Expression>,
8647}
8648
8649/// AlgorithmProperty
8650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8651#[cfg_attr(feature = "bindings", derive(TS))]
8652pub struct AlgorithmProperty {
8653    pub this: Box<Expression>,
8654}
8655
8656/// AutoIncrementProperty
8657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8658#[cfg_attr(feature = "bindings", derive(TS))]
8659pub struct AutoIncrementProperty {
8660    pub this: Box<Expression>,
8661}
8662
8663/// AutoRefreshProperty
8664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8665#[cfg_attr(feature = "bindings", derive(TS))]
8666pub struct AutoRefreshProperty {
8667    pub this: Box<Expression>,
8668}
8669
8670/// BackupProperty
8671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8672#[cfg_attr(feature = "bindings", derive(TS))]
8673pub struct BackupProperty {
8674    pub this: Box<Expression>,
8675}
8676
8677/// BuildProperty
8678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8679#[cfg_attr(feature = "bindings", derive(TS))]
8680pub struct BuildProperty {
8681    pub this: Box<Expression>,
8682}
8683
8684/// BlockCompressionProperty
8685#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8686#[cfg_attr(feature = "bindings", derive(TS))]
8687pub struct BlockCompressionProperty {
8688    #[serde(default)]
8689    pub autotemp: Option<Box<Expression>>,
8690    #[serde(default)]
8691    pub always: Option<Box<Expression>>,
8692    #[serde(default)]
8693    pub default: Option<Box<Expression>>,
8694    #[serde(default)]
8695    pub manual: Option<Box<Expression>>,
8696    #[serde(default)]
8697    pub never: Option<Box<Expression>>,
8698}
8699
8700/// CharacterSetProperty
8701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8702#[cfg_attr(feature = "bindings", derive(TS))]
8703pub struct CharacterSetProperty {
8704    pub this: Box<Expression>,
8705    #[serde(default)]
8706    pub default: Option<Box<Expression>>,
8707}
8708
8709/// ChecksumProperty
8710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8711#[cfg_attr(feature = "bindings", derive(TS))]
8712pub struct ChecksumProperty {
8713    #[serde(default)]
8714    pub on: Option<Box<Expression>>,
8715    #[serde(default)]
8716    pub default: Option<Box<Expression>>,
8717}
8718
8719/// CollateProperty
8720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8721#[cfg_attr(feature = "bindings", derive(TS))]
8722pub struct CollateProperty {
8723    pub this: Box<Expression>,
8724    #[serde(default)]
8725    pub default: Option<Box<Expression>>,
8726}
8727
8728/// DataBlocksizeProperty
8729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8730#[cfg_attr(feature = "bindings", derive(TS))]
8731pub struct DataBlocksizeProperty {
8732    #[serde(default)]
8733    pub size: Option<i64>,
8734    #[serde(default)]
8735    pub units: Option<Box<Expression>>,
8736    #[serde(default)]
8737    pub minimum: Option<Box<Expression>>,
8738    #[serde(default)]
8739    pub maximum: Option<Box<Expression>>,
8740    #[serde(default)]
8741    pub default: Option<Box<Expression>>,
8742}
8743
8744/// DataDeletionProperty
8745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8746#[cfg_attr(feature = "bindings", derive(TS))]
8747pub struct DataDeletionProperty {
8748    pub on: Box<Expression>,
8749    #[serde(default)]
8750    pub filter_column: Option<Box<Expression>>,
8751    #[serde(default)]
8752    pub retention_period: Option<Box<Expression>>,
8753}
8754
8755/// DefinerProperty
8756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8757#[cfg_attr(feature = "bindings", derive(TS))]
8758pub struct DefinerProperty {
8759    pub this: Box<Expression>,
8760}
8761
8762/// DistKeyProperty
8763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8764#[cfg_attr(feature = "bindings", derive(TS))]
8765pub struct DistKeyProperty {
8766    pub this: Box<Expression>,
8767}
8768
8769/// DistributedByProperty
8770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8771#[cfg_attr(feature = "bindings", derive(TS))]
8772pub struct DistributedByProperty {
8773    #[serde(default)]
8774    pub expressions: Vec<Expression>,
8775    pub kind: String,
8776    #[serde(default)]
8777    pub buckets: Option<Box<Expression>>,
8778    #[serde(default)]
8779    pub order: Option<Box<Expression>>,
8780}
8781
8782/// DistStyleProperty
8783#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8784#[cfg_attr(feature = "bindings", derive(TS))]
8785pub struct DistStyleProperty {
8786    pub this: Box<Expression>,
8787}
8788
8789/// DuplicateKeyProperty
8790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8791#[cfg_attr(feature = "bindings", derive(TS))]
8792pub struct DuplicateKeyProperty {
8793    #[serde(default)]
8794    pub expressions: Vec<Expression>,
8795}
8796
8797/// EngineProperty
8798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8799#[cfg_attr(feature = "bindings", derive(TS))]
8800pub struct EngineProperty {
8801    pub this: Box<Expression>,
8802}
8803
8804/// ToTableProperty
8805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8806#[cfg_attr(feature = "bindings", derive(TS))]
8807pub struct ToTableProperty {
8808    pub this: Box<Expression>,
8809}
8810
8811/// ExecuteAsProperty
8812#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8813#[cfg_attr(feature = "bindings", derive(TS))]
8814pub struct ExecuteAsProperty {
8815    pub this: Box<Expression>,
8816}
8817
8818/// ExternalProperty
8819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8820#[cfg_attr(feature = "bindings", derive(TS))]
8821pub struct ExternalProperty {
8822    #[serde(default)]
8823    pub this: Option<Box<Expression>>,
8824}
8825
8826/// FallbackProperty
8827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8828#[cfg_attr(feature = "bindings", derive(TS))]
8829pub struct FallbackProperty {
8830    #[serde(default)]
8831    pub no: Option<Box<Expression>>,
8832    #[serde(default)]
8833    pub protection: Option<Box<Expression>>,
8834}
8835
8836/// FileFormatProperty
8837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8838#[cfg_attr(feature = "bindings", derive(TS))]
8839pub struct FileFormatProperty {
8840    #[serde(default)]
8841    pub this: Option<Box<Expression>>,
8842    #[serde(default)]
8843    pub expressions: Vec<Expression>,
8844    #[serde(default)]
8845    pub hive_format: Option<Box<Expression>>,
8846}
8847
8848/// CredentialsProperty
8849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8850#[cfg_attr(feature = "bindings", derive(TS))]
8851pub struct CredentialsProperty {
8852    #[serde(default)]
8853    pub expressions: Vec<Expression>,
8854}
8855
8856/// FreespaceProperty
8857#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8858#[cfg_attr(feature = "bindings", derive(TS))]
8859pub struct FreespaceProperty {
8860    pub this: Box<Expression>,
8861    #[serde(default)]
8862    pub percent: Option<Box<Expression>>,
8863}
8864
8865/// InheritsProperty
8866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8867#[cfg_attr(feature = "bindings", derive(TS))]
8868pub struct InheritsProperty {
8869    #[serde(default)]
8870    pub expressions: Vec<Expression>,
8871}
8872
8873/// InputModelProperty
8874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8875#[cfg_attr(feature = "bindings", derive(TS))]
8876pub struct InputModelProperty {
8877    pub this: Box<Expression>,
8878}
8879
8880/// OutputModelProperty
8881#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8882#[cfg_attr(feature = "bindings", derive(TS))]
8883pub struct OutputModelProperty {
8884    pub this: Box<Expression>,
8885}
8886
8887/// IsolatedLoadingProperty
8888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8889#[cfg_attr(feature = "bindings", derive(TS))]
8890pub struct IsolatedLoadingProperty {
8891    #[serde(default)]
8892    pub no: Option<Box<Expression>>,
8893    #[serde(default)]
8894    pub concurrent: Option<Box<Expression>>,
8895    #[serde(default)]
8896    pub target: Option<Box<Expression>>,
8897}
8898
8899/// JournalProperty
8900#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8901#[cfg_attr(feature = "bindings", derive(TS))]
8902pub struct JournalProperty {
8903    #[serde(default)]
8904    pub no: Option<Box<Expression>>,
8905    #[serde(default)]
8906    pub dual: Option<Box<Expression>>,
8907    #[serde(default)]
8908    pub before: Option<Box<Expression>>,
8909    #[serde(default)]
8910    pub local: Option<Box<Expression>>,
8911    #[serde(default)]
8912    pub after: Option<Box<Expression>>,
8913}
8914
8915/// LanguageProperty
8916#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8917#[cfg_attr(feature = "bindings", derive(TS))]
8918pub struct LanguageProperty {
8919    pub this: Box<Expression>,
8920}
8921
8922/// EnviromentProperty
8923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8924#[cfg_attr(feature = "bindings", derive(TS))]
8925pub struct EnviromentProperty {
8926    #[serde(default)]
8927    pub expressions: Vec<Expression>,
8928}
8929
8930/// ClusteredByProperty
8931#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8932#[cfg_attr(feature = "bindings", derive(TS))]
8933pub struct ClusteredByProperty {
8934    #[serde(default)]
8935    pub expressions: Vec<Expression>,
8936    #[serde(default)]
8937    pub sorted_by: Option<Box<Expression>>,
8938    #[serde(default)]
8939    pub buckets: Option<Box<Expression>>,
8940}
8941
8942/// DictProperty
8943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8944#[cfg_attr(feature = "bindings", derive(TS))]
8945pub struct DictProperty {
8946    pub this: Box<Expression>,
8947    pub kind: String,
8948    #[serde(default)]
8949    pub settings: Option<Box<Expression>>,
8950}
8951
8952/// DictRange
8953#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8954#[cfg_attr(feature = "bindings", derive(TS))]
8955pub struct DictRange {
8956    pub this: Box<Expression>,
8957    #[serde(default)]
8958    pub min: Option<Box<Expression>>,
8959    #[serde(default)]
8960    pub max: Option<Box<Expression>>,
8961}
8962
8963/// OnCluster
8964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8965#[cfg_attr(feature = "bindings", derive(TS))]
8966pub struct OnCluster {
8967    pub this: Box<Expression>,
8968}
8969
8970/// LikeProperty
8971#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8972#[cfg_attr(feature = "bindings", derive(TS))]
8973pub struct LikeProperty {
8974    pub this: Box<Expression>,
8975    #[serde(default)]
8976    pub expressions: Vec<Expression>,
8977}
8978
8979/// LocationProperty
8980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8981#[cfg_attr(feature = "bindings", derive(TS))]
8982pub struct LocationProperty {
8983    pub this: Box<Expression>,
8984}
8985
8986/// LockProperty
8987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8988#[cfg_attr(feature = "bindings", derive(TS))]
8989pub struct LockProperty {
8990    pub this: Box<Expression>,
8991}
8992
8993/// LockingProperty
8994#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8995#[cfg_attr(feature = "bindings", derive(TS))]
8996pub struct LockingProperty {
8997    #[serde(default)]
8998    pub this: Option<Box<Expression>>,
8999    pub kind: String,
9000    #[serde(default)]
9001    pub for_or_in: Option<Box<Expression>>,
9002    #[serde(default)]
9003    pub lock_type: Option<Box<Expression>>,
9004    #[serde(default)]
9005    pub override_: Option<Box<Expression>>,
9006}
9007
9008/// LogProperty
9009#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9010#[cfg_attr(feature = "bindings", derive(TS))]
9011pub struct LogProperty {
9012    #[serde(default)]
9013    pub no: Option<Box<Expression>>,
9014}
9015
9016/// MaterializedProperty
9017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9018#[cfg_attr(feature = "bindings", derive(TS))]
9019pub struct MaterializedProperty {
9020    #[serde(default)]
9021    pub this: Option<Box<Expression>>,
9022}
9023
9024/// MergeBlockRatioProperty
9025#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9026#[cfg_attr(feature = "bindings", derive(TS))]
9027pub struct MergeBlockRatioProperty {
9028    #[serde(default)]
9029    pub this: Option<Box<Expression>>,
9030    #[serde(default)]
9031    pub no: Option<Box<Expression>>,
9032    #[serde(default)]
9033    pub default: Option<Box<Expression>>,
9034    #[serde(default)]
9035    pub percent: Option<Box<Expression>>,
9036}
9037
9038/// OnProperty
9039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9040#[cfg_attr(feature = "bindings", derive(TS))]
9041pub struct OnProperty {
9042    pub this: Box<Expression>,
9043}
9044
9045/// OnCommitProperty
9046#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9047#[cfg_attr(feature = "bindings", derive(TS))]
9048pub struct OnCommitProperty {
9049    #[serde(default)]
9050    pub delete: Option<Box<Expression>>,
9051}
9052
9053/// PartitionedByProperty
9054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9055#[cfg_attr(feature = "bindings", derive(TS))]
9056pub struct PartitionedByProperty {
9057    pub this: Box<Expression>,
9058}
9059
9060/// BigQuery PARTITION BY property in CREATE TABLE statements.
9061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9062#[cfg_attr(feature = "bindings", derive(TS))]
9063pub struct PartitionByProperty {
9064    #[serde(default)]
9065    pub expressions: Vec<Expression>,
9066}
9067
9068/// PartitionedByBucket
9069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9070#[cfg_attr(feature = "bindings", derive(TS))]
9071pub struct PartitionedByBucket {
9072    pub this: Box<Expression>,
9073    pub expression: Box<Expression>,
9074}
9075
9076/// BigQuery CLUSTER BY property in CREATE TABLE statements.
9077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9078#[cfg_attr(feature = "bindings", derive(TS))]
9079pub struct ClusterByColumnsProperty {
9080    #[serde(default)]
9081    pub columns: Vec<Identifier>,
9082}
9083
9084/// PartitionByTruncate
9085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9086#[cfg_attr(feature = "bindings", derive(TS))]
9087pub struct PartitionByTruncate {
9088    pub this: Box<Expression>,
9089    pub expression: Box<Expression>,
9090}
9091
9092/// PartitionByRangeProperty
9093#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9094#[cfg_attr(feature = "bindings", derive(TS))]
9095pub struct PartitionByRangeProperty {
9096    #[serde(default)]
9097    pub partition_expressions: Option<Box<Expression>>,
9098    #[serde(default)]
9099    pub create_expressions: Option<Box<Expression>>,
9100}
9101
9102/// PartitionByRangePropertyDynamic
9103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9104#[cfg_attr(feature = "bindings", derive(TS))]
9105pub struct PartitionByRangePropertyDynamic {
9106    #[serde(default)]
9107    pub this: Option<Box<Expression>>,
9108    #[serde(default)]
9109    pub start: Option<Box<Expression>>,
9110    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9111    #[serde(default)]
9112    pub use_start_end: bool,
9113    #[serde(default)]
9114    pub end: Option<Box<Expression>>,
9115    #[serde(default)]
9116    pub every: Option<Box<Expression>>,
9117}
9118
9119/// PartitionByListProperty
9120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9121#[cfg_attr(feature = "bindings", derive(TS))]
9122pub struct PartitionByListProperty {
9123    #[serde(default)]
9124    pub partition_expressions: Option<Box<Expression>>,
9125    #[serde(default)]
9126    pub create_expressions: Option<Box<Expression>>,
9127}
9128
9129/// PartitionList
9130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9131#[cfg_attr(feature = "bindings", derive(TS))]
9132pub struct PartitionList {
9133    pub this: Box<Expression>,
9134    #[serde(default)]
9135    pub expressions: Vec<Expression>,
9136}
9137
9138/// Partition - represents PARTITION/SUBPARTITION clause
9139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9140#[cfg_attr(feature = "bindings", derive(TS))]
9141pub struct Partition {
9142    pub expressions: Vec<Expression>,
9143    #[serde(default)]
9144    pub subpartition: bool,
9145}
9146
9147/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9148/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9150#[cfg_attr(feature = "bindings", derive(TS))]
9151pub struct RefreshTriggerProperty {
9152    /// Method: COMPLETE or AUTO
9153    pub method: String,
9154    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9155    #[serde(default)]
9156    pub kind: Option<String>,
9157    /// For SCHEDULE: EVERY n (the number)
9158    #[serde(default)]
9159    pub every: Option<Box<Expression>>,
9160    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9161    #[serde(default)]
9162    pub unit: Option<String>,
9163    /// For SCHEDULE: STARTS 'datetime'
9164    #[serde(default)]
9165    pub starts: Option<Box<Expression>>,
9166}
9167
9168/// UniqueKeyProperty
9169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9170#[cfg_attr(feature = "bindings", derive(TS))]
9171pub struct UniqueKeyProperty {
9172    #[serde(default)]
9173    pub expressions: Vec<Expression>,
9174}
9175
9176/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9178#[cfg_attr(feature = "bindings", derive(TS))]
9179pub struct RollupProperty {
9180    pub expressions: Vec<RollupIndex>,
9181}
9182
9183/// RollupIndex - A single rollup index: name(col1, col2)
9184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9185#[cfg_attr(feature = "bindings", derive(TS))]
9186pub struct RollupIndex {
9187    pub name: Identifier,
9188    pub expressions: Vec<Identifier>,
9189}
9190
9191/// PartitionBoundSpec
9192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9193#[cfg_attr(feature = "bindings", derive(TS))]
9194pub struct PartitionBoundSpec {
9195    #[serde(default)]
9196    pub this: Option<Box<Expression>>,
9197    #[serde(default)]
9198    pub expression: Option<Box<Expression>>,
9199    #[serde(default)]
9200    pub from_expressions: Option<Box<Expression>>,
9201    #[serde(default)]
9202    pub to_expressions: Option<Box<Expression>>,
9203}
9204
9205/// PartitionedOfProperty
9206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9207#[cfg_attr(feature = "bindings", derive(TS))]
9208pub struct PartitionedOfProperty {
9209    pub this: Box<Expression>,
9210    pub expression: Box<Expression>,
9211}
9212
9213/// RemoteWithConnectionModelProperty
9214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9215#[cfg_attr(feature = "bindings", derive(TS))]
9216pub struct RemoteWithConnectionModelProperty {
9217    pub this: Box<Expression>,
9218}
9219
9220/// ReturnsProperty
9221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9222#[cfg_attr(feature = "bindings", derive(TS))]
9223pub struct ReturnsProperty {
9224    #[serde(default)]
9225    pub this: Option<Box<Expression>>,
9226    #[serde(default)]
9227    pub is_table: Option<Box<Expression>>,
9228    #[serde(default)]
9229    pub table: Option<Box<Expression>>,
9230    #[serde(default)]
9231    pub null: Option<Box<Expression>>,
9232}
9233
9234/// RowFormatProperty
9235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9236#[cfg_attr(feature = "bindings", derive(TS))]
9237pub struct RowFormatProperty {
9238    pub this: Box<Expression>,
9239}
9240
9241/// RowFormatDelimitedProperty
9242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9243#[cfg_attr(feature = "bindings", derive(TS))]
9244pub struct RowFormatDelimitedProperty {
9245    #[serde(default)]
9246    pub fields: Option<Box<Expression>>,
9247    #[serde(default)]
9248    pub escaped: Option<Box<Expression>>,
9249    #[serde(default)]
9250    pub collection_items: Option<Box<Expression>>,
9251    #[serde(default)]
9252    pub map_keys: Option<Box<Expression>>,
9253    #[serde(default)]
9254    pub lines: Option<Box<Expression>>,
9255    #[serde(default)]
9256    pub null: Option<Box<Expression>>,
9257    #[serde(default)]
9258    pub serde: Option<Box<Expression>>,
9259}
9260
9261/// RowFormatSerdeProperty
9262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9263#[cfg_attr(feature = "bindings", derive(TS))]
9264pub struct RowFormatSerdeProperty {
9265    pub this: Box<Expression>,
9266    #[serde(default)]
9267    pub serde_properties: Option<Box<Expression>>,
9268}
9269
9270/// QueryTransform
9271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9272#[cfg_attr(feature = "bindings", derive(TS))]
9273pub struct QueryTransform {
9274    #[serde(default)]
9275    pub expressions: Vec<Expression>,
9276    #[serde(default)]
9277    pub command_script: Option<Box<Expression>>,
9278    #[serde(default)]
9279    pub schema: Option<Box<Expression>>,
9280    #[serde(default)]
9281    pub row_format_before: Option<Box<Expression>>,
9282    #[serde(default)]
9283    pub record_writer: Option<Box<Expression>>,
9284    #[serde(default)]
9285    pub row_format_after: Option<Box<Expression>>,
9286    #[serde(default)]
9287    pub record_reader: Option<Box<Expression>>,
9288}
9289
9290/// SampleProperty
9291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9292#[cfg_attr(feature = "bindings", derive(TS))]
9293pub struct SampleProperty {
9294    pub this: Box<Expression>,
9295}
9296
9297/// SecurityProperty
9298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9299#[cfg_attr(feature = "bindings", derive(TS))]
9300pub struct SecurityProperty {
9301    pub this: Box<Expression>,
9302}
9303
9304/// SchemaCommentProperty
9305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9306#[cfg_attr(feature = "bindings", derive(TS))]
9307pub struct SchemaCommentProperty {
9308    pub this: Box<Expression>,
9309}
9310
9311/// SemanticView
9312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9313#[cfg_attr(feature = "bindings", derive(TS))]
9314pub struct SemanticView {
9315    pub this: Box<Expression>,
9316    #[serde(default)]
9317    pub metrics: Option<Box<Expression>>,
9318    #[serde(default)]
9319    pub dimensions: Option<Box<Expression>>,
9320    #[serde(default)]
9321    pub facts: Option<Box<Expression>>,
9322    #[serde(default)]
9323    pub where_: Option<Box<Expression>>,
9324}
9325
9326/// SerdeProperties
9327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9328#[cfg_attr(feature = "bindings", derive(TS))]
9329pub struct SerdeProperties {
9330    #[serde(default)]
9331    pub expressions: Vec<Expression>,
9332    #[serde(default)]
9333    pub with_: Option<Box<Expression>>,
9334}
9335
9336/// SetProperty
9337#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9338#[cfg_attr(feature = "bindings", derive(TS))]
9339pub struct SetProperty {
9340    #[serde(default)]
9341    pub multi: Option<Box<Expression>>,
9342}
9343
9344/// SharingProperty
9345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9346#[cfg_attr(feature = "bindings", derive(TS))]
9347pub struct SharingProperty {
9348    #[serde(default)]
9349    pub this: Option<Box<Expression>>,
9350}
9351
9352/// SetConfigProperty
9353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9354#[cfg_attr(feature = "bindings", derive(TS))]
9355pub struct SetConfigProperty {
9356    pub this: Box<Expression>,
9357}
9358
9359/// SettingsProperty
9360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9361#[cfg_attr(feature = "bindings", derive(TS))]
9362pub struct SettingsProperty {
9363    #[serde(default)]
9364    pub expressions: Vec<Expression>,
9365}
9366
9367/// SortKeyProperty
9368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9369#[cfg_attr(feature = "bindings", derive(TS))]
9370pub struct SortKeyProperty {
9371    pub this: Box<Expression>,
9372    #[serde(default)]
9373    pub compound: Option<Box<Expression>>,
9374}
9375
9376/// SqlReadWriteProperty
9377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9378#[cfg_attr(feature = "bindings", derive(TS))]
9379pub struct SqlReadWriteProperty {
9380    pub this: Box<Expression>,
9381}
9382
9383/// SqlSecurityProperty
9384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9385#[cfg_attr(feature = "bindings", derive(TS))]
9386pub struct SqlSecurityProperty {
9387    pub this: Box<Expression>,
9388}
9389
9390/// StabilityProperty
9391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9392#[cfg_attr(feature = "bindings", derive(TS))]
9393pub struct StabilityProperty {
9394    pub this: Box<Expression>,
9395}
9396
9397/// StorageHandlerProperty
9398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9399#[cfg_attr(feature = "bindings", derive(TS))]
9400pub struct StorageHandlerProperty {
9401    pub this: Box<Expression>,
9402}
9403
9404/// TemporaryProperty
9405#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9406#[cfg_attr(feature = "bindings", derive(TS))]
9407pub struct TemporaryProperty {
9408    #[serde(default)]
9409    pub this: Option<Box<Expression>>,
9410}
9411
9412/// Tags
9413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9414#[cfg_attr(feature = "bindings", derive(TS))]
9415pub struct Tags {
9416    #[serde(default)]
9417    pub expressions: Vec<Expression>,
9418}
9419
9420/// TransformModelProperty
9421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9422#[cfg_attr(feature = "bindings", derive(TS))]
9423pub struct TransformModelProperty {
9424    #[serde(default)]
9425    pub expressions: Vec<Expression>,
9426}
9427
9428/// TransientProperty
9429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9430#[cfg_attr(feature = "bindings", derive(TS))]
9431pub struct TransientProperty {
9432    #[serde(default)]
9433    pub this: Option<Box<Expression>>,
9434}
9435
9436/// UsingTemplateProperty
9437#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9438#[cfg_attr(feature = "bindings", derive(TS))]
9439pub struct UsingTemplateProperty {
9440    pub this: Box<Expression>,
9441}
9442
9443/// ViewAttributeProperty
9444#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9445#[cfg_attr(feature = "bindings", derive(TS))]
9446pub struct ViewAttributeProperty {
9447    pub this: Box<Expression>,
9448}
9449
9450/// VolatileProperty
9451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9452#[cfg_attr(feature = "bindings", derive(TS))]
9453pub struct VolatileProperty {
9454    #[serde(default)]
9455    pub this: Option<Box<Expression>>,
9456}
9457
9458/// WithDataProperty
9459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9460#[cfg_attr(feature = "bindings", derive(TS))]
9461pub struct WithDataProperty {
9462    #[serde(default)]
9463    pub no: Option<Box<Expression>>,
9464    #[serde(default)]
9465    pub statistics: Option<Box<Expression>>,
9466}
9467
9468/// WithJournalTableProperty
9469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9470#[cfg_attr(feature = "bindings", derive(TS))]
9471pub struct WithJournalTableProperty {
9472    pub this: Box<Expression>,
9473}
9474
9475/// WithSchemaBindingProperty
9476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9477#[cfg_attr(feature = "bindings", derive(TS))]
9478pub struct WithSchemaBindingProperty {
9479    pub this: Box<Expression>,
9480}
9481
9482/// WithSystemVersioningProperty
9483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9484#[cfg_attr(feature = "bindings", derive(TS))]
9485pub struct WithSystemVersioningProperty {
9486    #[serde(default)]
9487    pub on: Option<Box<Expression>>,
9488    #[serde(default)]
9489    pub this: Option<Box<Expression>>,
9490    #[serde(default)]
9491    pub data_consistency: Option<Box<Expression>>,
9492    #[serde(default)]
9493    pub retention_period: Option<Box<Expression>>,
9494    #[serde(default)]
9495    pub with_: Option<Box<Expression>>,
9496}
9497
9498/// WithProcedureOptions
9499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9500#[cfg_attr(feature = "bindings", derive(TS))]
9501pub struct WithProcedureOptions {
9502    #[serde(default)]
9503    pub expressions: Vec<Expression>,
9504}
9505
9506/// EncodeProperty
9507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9508#[cfg_attr(feature = "bindings", derive(TS))]
9509pub struct EncodeProperty {
9510    pub this: Box<Expression>,
9511    #[serde(default)]
9512    pub properties: Vec<Expression>,
9513    #[serde(default)]
9514    pub key: Option<Box<Expression>>,
9515}
9516
9517/// IncludeProperty
9518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9519#[cfg_attr(feature = "bindings", derive(TS))]
9520pub struct IncludeProperty {
9521    pub this: Box<Expression>,
9522    #[serde(default)]
9523    pub alias: Option<String>,
9524    #[serde(default)]
9525    pub column_def: Option<Box<Expression>>,
9526}
9527
9528/// Properties
9529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9530#[cfg_attr(feature = "bindings", derive(TS))]
9531pub struct Properties {
9532    #[serde(default)]
9533    pub expressions: Vec<Expression>,
9534}
9535
9536/// Key/value pair in a BigQuery OPTIONS (...) clause.
9537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9538#[cfg_attr(feature = "bindings", derive(TS))]
9539pub struct OptionEntry {
9540    pub key: Identifier,
9541    pub value: Expression,
9542}
9543
9544/// Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
9545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9546#[cfg_attr(feature = "bindings", derive(TS))]
9547pub struct OptionsProperty {
9548    #[serde(default)]
9549    pub entries: Vec<OptionEntry>,
9550}
9551
9552/// InputOutputFormat
9553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9554#[cfg_attr(feature = "bindings", derive(TS))]
9555pub struct InputOutputFormat {
9556    #[serde(default)]
9557    pub input_format: Option<Box<Expression>>,
9558    #[serde(default)]
9559    pub output_format: Option<Box<Expression>>,
9560}
9561
9562/// Reference
9563#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9564#[cfg_attr(feature = "bindings", derive(TS))]
9565pub struct Reference {
9566    pub this: Box<Expression>,
9567    #[serde(default)]
9568    pub expressions: Vec<Expression>,
9569    #[serde(default)]
9570    pub options: Vec<Expression>,
9571}
9572
9573/// QueryOption
9574#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9575#[cfg_attr(feature = "bindings", derive(TS))]
9576pub struct QueryOption {
9577    pub this: Box<Expression>,
9578    #[serde(default)]
9579    pub expression: Option<Box<Expression>>,
9580}
9581
9582/// WithTableHint
9583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9584#[cfg_attr(feature = "bindings", derive(TS))]
9585pub struct WithTableHint {
9586    #[serde(default)]
9587    pub expressions: Vec<Expression>,
9588}
9589
9590/// IndexTableHint
9591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9592#[cfg_attr(feature = "bindings", derive(TS))]
9593pub struct IndexTableHint {
9594    pub this: Box<Expression>,
9595    #[serde(default)]
9596    pub expressions: Vec<Expression>,
9597    #[serde(default)]
9598    pub target: Option<Box<Expression>>,
9599}
9600
9601/// Get
9602#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9603#[cfg_attr(feature = "bindings", derive(TS))]
9604pub struct Get {
9605    pub this: Box<Expression>,
9606    #[serde(default)]
9607    pub target: Option<Box<Expression>>,
9608    #[serde(default)]
9609    pub properties: Vec<Expression>,
9610}
9611
9612/// SetOperation
9613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9614#[cfg_attr(feature = "bindings", derive(TS))]
9615pub struct SetOperation {
9616    #[serde(default)]
9617    pub with_: Option<Box<Expression>>,
9618    pub this: Box<Expression>,
9619    pub expression: Box<Expression>,
9620    #[serde(default)]
9621    pub distinct: bool,
9622    #[serde(default)]
9623    pub by_name: Option<Box<Expression>>,
9624    #[serde(default)]
9625    pub side: Option<Box<Expression>>,
9626    #[serde(default)]
9627    pub kind: Option<String>,
9628    #[serde(default)]
9629    pub on: Option<Box<Expression>>,
9630}
9631
9632/// Var - Simple variable reference (for SQL variables, keywords as values)
9633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9634#[cfg_attr(feature = "bindings", derive(TS))]
9635pub struct Var {
9636    pub this: String,
9637}
9638
9639/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
9640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9641#[cfg_attr(feature = "bindings", derive(TS))]
9642pub struct Variadic {
9643    pub this: Box<Expression>,
9644}
9645
9646/// Version
9647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9648#[cfg_attr(feature = "bindings", derive(TS))]
9649pub struct Version {
9650    pub this: Box<Expression>,
9651    pub kind: String,
9652    #[serde(default)]
9653    pub expression: Option<Box<Expression>>,
9654}
9655
9656/// Schema
9657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9658#[cfg_attr(feature = "bindings", derive(TS))]
9659pub struct Schema {
9660    #[serde(default)]
9661    pub this: Option<Box<Expression>>,
9662    #[serde(default)]
9663    pub expressions: Vec<Expression>,
9664}
9665
9666/// Lock
9667#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9668#[cfg_attr(feature = "bindings", derive(TS))]
9669pub struct Lock {
9670    #[serde(default)]
9671    pub update: Option<Box<Expression>>,
9672    #[serde(default)]
9673    pub expressions: Vec<Expression>,
9674    #[serde(default)]
9675    pub wait: Option<Box<Expression>>,
9676    #[serde(default)]
9677    pub key: Option<Box<Expression>>,
9678}
9679
9680/// TableSample - wraps an expression with a TABLESAMPLE clause
9681/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
9682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9683#[cfg_attr(feature = "bindings", derive(TS))]
9684pub struct TableSample {
9685    /// The expression being sampled (subquery, function, etc.)
9686    #[serde(default, skip_serializing_if = "Option::is_none")]
9687    pub this: Option<Box<Expression>>,
9688    /// The sample specification
9689    #[serde(default, skip_serializing_if = "Option::is_none")]
9690    pub sample: Option<Box<Sample>>,
9691    #[serde(default)]
9692    pub expressions: Vec<Expression>,
9693    #[serde(default)]
9694    pub method: Option<String>,
9695    #[serde(default)]
9696    pub bucket_numerator: Option<Box<Expression>>,
9697    #[serde(default)]
9698    pub bucket_denominator: Option<Box<Expression>>,
9699    #[serde(default)]
9700    pub bucket_field: Option<Box<Expression>>,
9701    #[serde(default)]
9702    pub percent: Option<Box<Expression>>,
9703    #[serde(default)]
9704    pub rows: Option<Box<Expression>>,
9705    #[serde(default)]
9706    pub size: Option<i64>,
9707    #[serde(default)]
9708    pub seed: Option<Box<Expression>>,
9709}
9710
9711/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
9712#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9713#[cfg_attr(feature = "bindings", derive(TS))]
9714pub struct Tag {
9715    #[serde(default)]
9716    pub this: Option<Box<Expression>>,
9717    #[serde(default)]
9718    pub prefix: Option<Box<Expression>>,
9719    #[serde(default)]
9720    pub postfix: Option<Box<Expression>>,
9721}
9722
9723/// UnpivotColumns
9724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9725#[cfg_attr(feature = "bindings", derive(TS))]
9726pub struct UnpivotColumns {
9727    pub this: Box<Expression>,
9728    #[serde(default)]
9729    pub expressions: Vec<Expression>,
9730}
9731
9732/// SessionParameter
9733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9734#[cfg_attr(feature = "bindings", derive(TS))]
9735pub struct SessionParameter {
9736    pub this: Box<Expression>,
9737    #[serde(default)]
9738    pub kind: Option<String>,
9739}
9740
9741/// PseudoType
9742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9743#[cfg_attr(feature = "bindings", derive(TS))]
9744pub struct PseudoType {
9745    pub this: Box<Expression>,
9746}
9747
9748/// ObjectIdentifier
9749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9750#[cfg_attr(feature = "bindings", derive(TS))]
9751pub struct ObjectIdentifier {
9752    pub this: Box<Expression>,
9753}
9754
9755/// Transaction
9756#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9757#[cfg_attr(feature = "bindings", derive(TS))]
9758pub struct Transaction {
9759    #[serde(default)]
9760    pub this: Option<Box<Expression>>,
9761    #[serde(default)]
9762    pub modes: Option<Box<Expression>>,
9763    #[serde(default)]
9764    pub mark: Option<Box<Expression>>,
9765}
9766
9767/// Commit
9768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9769#[cfg_attr(feature = "bindings", derive(TS))]
9770pub struct Commit {
9771    #[serde(default)]
9772    pub chain: Option<Box<Expression>>,
9773    #[serde(default)]
9774    pub this: Option<Box<Expression>>,
9775    #[serde(default)]
9776    pub durability: Option<Box<Expression>>,
9777}
9778
9779/// Rollback
9780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9781#[cfg_attr(feature = "bindings", derive(TS))]
9782pub struct Rollback {
9783    #[serde(default)]
9784    pub savepoint: Option<Box<Expression>>,
9785    #[serde(default)]
9786    pub this: Option<Box<Expression>>,
9787}
9788
9789/// AlterSession
9790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9791#[cfg_attr(feature = "bindings", derive(TS))]
9792pub struct AlterSession {
9793    #[serde(default)]
9794    pub expressions: Vec<Expression>,
9795    #[serde(default)]
9796    pub unset: Option<Box<Expression>>,
9797}
9798
9799/// Analyze
9800#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9801#[cfg_attr(feature = "bindings", derive(TS))]
9802pub struct Analyze {
9803    #[serde(default)]
9804    pub kind: Option<String>,
9805    #[serde(default)]
9806    pub this: Option<Box<Expression>>,
9807    #[serde(default)]
9808    pub options: Vec<Expression>,
9809    #[serde(default)]
9810    pub mode: Option<Box<Expression>>,
9811    #[serde(default)]
9812    pub partition: Option<Box<Expression>>,
9813    #[serde(default)]
9814    pub expression: Option<Box<Expression>>,
9815    #[serde(default)]
9816    pub properties: Vec<Expression>,
9817    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
9818    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9819    pub columns: Vec<String>,
9820}
9821
9822/// AnalyzeStatistics
9823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9824#[cfg_attr(feature = "bindings", derive(TS))]
9825pub struct AnalyzeStatistics {
9826    pub kind: String,
9827    #[serde(default)]
9828    pub option: Option<Box<Expression>>,
9829    #[serde(default)]
9830    pub this: Option<Box<Expression>>,
9831    #[serde(default)]
9832    pub expressions: Vec<Expression>,
9833}
9834
9835/// AnalyzeHistogram
9836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9837#[cfg_attr(feature = "bindings", derive(TS))]
9838pub struct AnalyzeHistogram {
9839    pub this: Box<Expression>,
9840    #[serde(default)]
9841    pub expressions: Vec<Expression>,
9842    #[serde(default)]
9843    pub expression: Option<Box<Expression>>,
9844    #[serde(default)]
9845    pub update_options: Option<Box<Expression>>,
9846}
9847
9848/// AnalyzeSample
9849#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9850#[cfg_attr(feature = "bindings", derive(TS))]
9851pub struct AnalyzeSample {
9852    pub kind: String,
9853    #[serde(default)]
9854    pub sample: Option<Box<Expression>>,
9855}
9856
9857/// AnalyzeListChainedRows
9858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9859#[cfg_attr(feature = "bindings", derive(TS))]
9860pub struct AnalyzeListChainedRows {
9861    #[serde(default)]
9862    pub expression: Option<Box<Expression>>,
9863}
9864
9865/// AnalyzeDelete
9866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9867#[cfg_attr(feature = "bindings", derive(TS))]
9868pub struct AnalyzeDelete {
9869    #[serde(default)]
9870    pub kind: Option<String>,
9871}
9872
9873/// AnalyzeWith
9874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9875#[cfg_attr(feature = "bindings", derive(TS))]
9876pub struct AnalyzeWith {
9877    #[serde(default)]
9878    pub expressions: Vec<Expression>,
9879}
9880
9881/// AnalyzeValidate
9882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9883#[cfg_attr(feature = "bindings", derive(TS))]
9884pub struct AnalyzeValidate {
9885    pub kind: String,
9886    #[serde(default)]
9887    pub this: Option<Box<Expression>>,
9888    #[serde(default)]
9889    pub expression: Option<Box<Expression>>,
9890}
9891
9892/// AddPartition
9893#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9894#[cfg_attr(feature = "bindings", derive(TS))]
9895pub struct AddPartition {
9896    pub this: Box<Expression>,
9897    #[serde(default)]
9898    pub exists: bool,
9899    #[serde(default)]
9900    pub location: Option<Box<Expression>>,
9901}
9902
9903/// AttachOption
9904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9905#[cfg_attr(feature = "bindings", derive(TS))]
9906pub struct AttachOption {
9907    pub this: Box<Expression>,
9908    #[serde(default)]
9909    pub expression: Option<Box<Expression>>,
9910}
9911
9912/// DropPartition
9913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9914#[cfg_attr(feature = "bindings", derive(TS))]
9915pub struct DropPartition {
9916    #[serde(default)]
9917    pub expressions: Vec<Expression>,
9918    #[serde(default)]
9919    pub exists: bool,
9920}
9921
9922/// ReplacePartition
9923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9924#[cfg_attr(feature = "bindings", derive(TS))]
9925pub struct ReplacePartition {
9926    pub expression: Box<Expression>,
9927    #[serde(default)]
9928    pub source: Option<Box<Expression>>,
9929}
9930
9931/// DPipe
9932#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9933#[cfg_attr(feature = "bindings", derive(TS))]
9934pub struct DPipe {
9935    pub this: Box<Expression>,
9936    pub expression: Box<Expression>,
9937    #[serde(default)]
9938    pub safe: Option<Box<Expression>>,
9939}
9940
9941/// Operator
9942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9943#[cfg_attr(feature = "bindings", derive(TS))]
9944pub struct Operator {
9945    pub this: Box<Expression>,
9946    #[serde(default)]
9947    pub operator: Option<Box<Expression>>,
9948    pub expression: Box<Expression>,
9949    /// Comments between OPERATOR() and the RHS expression
9950    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9951    pub comments: Vec<String>,
9952}
9953
9954/// PivotAny
9955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9956#[cfg_attr(feature = "bindings", derive(TS))]
9957pub struct PivotAny {
9958    #[serde(default)]
9959    pub this: Option<Box<Expression>>,
9960}
9961
9962/// Aliases
9963#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9964#[cfg_attr(feature = "bindings", derive(TS))]
9965pub struct Aliases {
9966    pub this: Box<Expression>,
9967    #[serde(default)]
9968    pub expressions: Vec<Expression>,
9969}
9970
9971/// AtIndex
9972#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9973#[cfg_attr(feature = "bindings", derive(TS))]
9974pub struct AtIndex {
9975    pub this: Box<Expression>,
9976    pub expression: Box<Expression>,
9977}
9978
9979/// FromTimeZone
9980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9981#[cfg_attr(feature = "bindings", derive(TS))]
9982pub struct FromTimeZone {
9983    pub this: Box<Expression>,
9984    #[serde(default)]
9985    pub zone: Option<Box<Expression>>,
9986}
9987
9988/// Format override for a column in Teradata
9989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9990#[cfg_attr(feature = "bindings", derive(TS))]
9991pub struct FormatPhrase {
9992    pub this: Box<Expression>,
9993    pub format: String,
9994}
9995
9996/// ForIn
9997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9998#[cfg_attr(feature = "bindings", derive(TS))]
9999pub struct ForIn {
10000    pub this: Box<Expression>,
10001    pub expression: Box<Expression>,
10002}
10003
10004/// Automatically converts unit arg into a var.
10005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10006#[cfg_attr(feature = "bindings", derive(TS))]
10007pub struct TimeUnit {
10008    #[serde(default)]
10009    pub unit: Option<String>,
10010}
10011
10012/// IntervalOp
10013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10014#[cfg_attr(feature = "bindings", derive(TS))]
10015pub struct IntervalOp {
10016    #[serde(default)]
10017    pub unit: Option<String>,
10018    pub expression: Box<Expression>,
10019}
10020
10021/// HavingMax
10022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10023#[cfg_attr(feature = "bindings", derive(TS))]
10024pub struct HavingMax {
10025    pub this: Box<Expression>,
10026    pub expression: Box<Expression>,
10027    #[serde(default)]
10028    pub max: Option<Box<Expression>>,
10029}
10030
10031/// CosineDistance
10032#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10033#[cfg_attr(feature = "bindings", derive(TS))]
10034pub struct CosineDistance {
10035    pub this: Box<Expression>,
10036    pub expression: Box<Expression>,
10037}
10038
10039/// DotProduct
10040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10041#[cfg_attr(feature = "bindings", derive(TS))]
10042pub struct DotProduct {
10043    pub this: Box<Expression>,
10044    pub expression: Box<Expression>,
10045}
10046
10047/// EuclideanDistance
10048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10049#[cfg_attr(feature = "bindings", derive(TS))]
10050pub struct EuclideanDistance {
10051    pub this: Box<Expression>,
10052    pub expression: Box<Expression>,
10053}
10054
10055/// ManhattanDistance
10056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10057#[cfg_attr(feature = "bindings", derive(TS))]
10058pub struct ManhattanDistance {
10059    pub this: Box<Expression>,
10060    pub expression: Box<Expression>,
10061}
10062
10063/// JarowinklerSimilarity
10064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10065#[cfg_attr(feature = "bindings", derive(TS))]
10066pub struct JarowinklerSimilarity {
10067    pub this: Box<Expression>,
10068    pub expression: Box<Expression>,
10069}
10070
10071/// Booland
10072#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10073#[cfg_attr(feature = "bindings", derive(TS))]
10074pub struct Booland {
10075    pub this: Box<Expression>,
10076    pub expression: Box<Expression>,
10077}
10078
10079/// Boolor
10080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10081#[cfg_attr(feature = "bindings", derive(TS))]
10082pub struct Boolor {
10083    pub this: Box<Expression>,
10084    pub expression: Box<Expression>,
10085}
10086
10087/// ParameterizedAgg
10088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10089#[cfg_attr(feature = "bindings", derive(TS))]
10090pub struct ParameterizedAgg {
10091    pub this: Box<Expression>,
10092    #[serde(default)]
10093    pub expressions: Vec<Expression>,
10094    #[serde(default)]
10095    pub params: Vec<Expression>,
10096}
10097
10098/// ArgMax
10099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10100#[cfg_attr(feature = "bindings", derive(TS))]
10101pub struct ArgMax {
10102    pub this: Box<Expression>,
10103    pub expression: Box<Expression>,
10104    #[serde(default)]
10105    pub count: Option<Box<Expression>>,
10106}
10107
10108/// ArgMin
10109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10110#[cfg_attr(feature = "bindings", derive(TS))]
10111pub struct ArgMin {
10112    pub this: Box<Expression>,
10113    pub expression: Box<Expression>,
10114    #[serde(default)]
10115    pub count: Option<Box<Expression>>,
10116}
10117
10118/// ApproxTopK
10119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10120#[cfg_attr(feature = "bindings", derive(TS))]
10121pub struct ApproxTopK {
10122    pub this: Box<Expression>,
10123    #[serde(default)]
10124    pub expression: Option<Box<Expression>>,
10125    #[serde(default)]
10126    pub counters: Option<Box<Expression>>,
10127}
10128
10129/// ApproxTopKAccumulate
10130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10131#[cfg_attr(feature = "bindings", derive(TS))]
10132pub struct ApproxTopKAccumulate {
10133    pub this: Box<Expression>,
10134    #[serde(default)]
10135    pub expression: Option<Box<Expression>>,
10136}
10137
10138/// ApproxTopKCombine
10139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10140#[cfg_attr(feature = "bindings", derive(TS))]
10141pub struct ApproxTopKCombine {
10142    pub this: Box<Expression>,
10143    #[serde(default)]
10144    pub expression: Option<Box<Expression>>,
10145}
10146
10147/// ApproxTopKEstimate
10148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10149#[cfg_attr(feature = "bindings", derive(TS))]
10150pub struct ApproxTopKEstimate {
10151    pub this: Box<Expression>,
10152    #[serde(default)]
10153    pub expression: Option<Box<Expression>>,
10154}
10155
10156/// ApproxTopSum
10157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10158#[cfg_attr(feature = "bindings", derive(TS))]
10159pub struct ApproxTopSum {
10160    pub this: Box<Expression>,
10161    pub expression: Box<Expression>,
10162    #[serde(default)]
10163    pub count: Option<Box<Expression>>,
10164}
10165
10166/// ApproxQuantiles
10167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10168#[cfg_attr(feature = "bindings", derive(TS))]
10169pub struct ApproxQuantiles {
10170    pub this: Box<Expression>,
10171    #[serde(default)]
10172    pub expression: Option<Box<Expression>>,
10173}
10174
10175/// Minhash
10176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10177#[cfg_attr(feature = "bindings", derive(TS))]
10178pub struct Minhash {
10179    pub this: Box<Expression>,
10180    #[serde(default)]
10181    pub expressions: Vec<Expression>,
10182}
10183
10184/// FarmFingerprint
10185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10186#[cfg_attr(feature = "bindings", derive(TS))]
10187pub struct FarmFingerprint {
10188    #[serde(default)]
10189    pub expressions: Vec<Expression>,
10190}
10191
10192/// Float64
10193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10194#[cfg_attr(feature = "bindings", derive(TS))]
10195pub struct Float64 {
10196    pub this: Box<Expression>,
10197    #[serde(default)]
10198    pub expression: Option<Box<Expression>>,
10199}
10200
10201/// Transform
10202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10203#[cfg_attr(feature = "bindings", derive(TS))]
10204pub struct Transform {
10205    pub this: Box<Expression>,
10206    pub expression: Box<Expression>,
10207}
10208
10209/// Translate
10210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10211#[cfg_attr(feature = "bindings", derive(TS))]
10212pub struct Translate {
10213    pub this: Box<Expression>,
10214    #[serde(default)]
10215    pub from_: Option<Box<Expression>>,
10216    #[serde(default)]
10217    pub to: Option<Box<Expression>>,
10218}
10219
10220/// Grouping
10221#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10222#[cfg_attr(feature = "bindings", derive(TS))]
10223pub struct Grouping {
10224    #[serde(default)]
10225    pub expressions: Vec<Expression>,
10226}
10227
10228/// GroupingId
10229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10230#[cfg_attr(feature = "bindings", derive(TS))]
10231pub struct GroupingId {
10232    #[serde(default)]
10233    pub expressions: Vec<Expression>,
10234}
10235
10236/// Anonymous
10237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10238#[cfg_attr(feature = "bindings", derive(TS))]
10239pub struct Anonymous {
10240    pub this: Box<Expression>,
10241    #[serde(default)]
10242    pub expressions: Vec<Expression>,
10243}
10244
10245/// AnonymousAggFunc
10246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10247#[cfg_attr(feature = "bindings", derive(TS))]
10248pub struct AnonymousAggFunc {
10249    pub this: Box<Expression>,
10250    #[serde(default)]
10251    pub expressions: Vec<Expression>,
10252}
10253
10254/// CombinedAggFunc
10255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10256#[cfg_attr(feature = "bindings", derive(TS))]
10257pub struct CombinedAggFunc {
10258    pub this: Box<Expression>,
10259    #[serde(default)]
10260    pub expressions: Vec<Expression>,
10261}
10262
10263/// CombinedParameterizedAgg
10264#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10265#[cfg_attr(feature = "bindings", derive(TS))]
10266pub struct CombinedParameterizedAgg {
10267    pub this: Box<Expression>,
10268    #[serde(default)]
10269    pub expressions: Vec<Expression>,
10270    #[serde(default)]
10271    pub params: Vec<Expression>,
10272}
10273
10274/// HashAgg
10275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10276#[cfg_attr(feature = "bindings", derive(TS))]
10277pub struct HashAgg {
10278    pub this: Box<Expression>,
10279    #[serde(default)]
10280    pub expressions: Vec<Expression>,
10281}
10282
10283/// Hll
10284#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10285#[cfg_attr(feature = "bindings", derive(TS))]
10286pub struct Hll {
10287    pub this: Box<Expression>,
10288    #[serde(default)]
10289    pub expressions: Vec<Expression>,
10290}
10291
10292/// Apply
10293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10294#[cfg_attr(feature = "bindings", derive(TS))]
10295pub struct Apply {
10296    pub this: Box<Expression>,
10297    pub expression: Box<Expression>,
10298}
10299
10300/// ToBoolean
10301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10302#[cfg_attr(feature = "bindings", derive(TS))]
10303pub struct ToBoolean {
10304    pub this: Box<Expression>,
10305    #[serde(default)]
10306    pub safe: Option<Box<Expression>>,
10307}
10308
10309/// List
10310#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10311#[cfg_attr(feature = "bindings", derive(TS))]
10312pub struct List {
10313    #[serde(default)]
10314    pub expressions: Vec<Expression>,
10315}
10316
10317/// ToMap - Materialize-style map constructor
10318/// Can hold either:
10319/// - A SELECT subquery (MAP(SELECT 'a', 1))
10320/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10322#[cfg_attr(feature = "bindings", derive(TS))]
10323pub struct ToMap {
10324    /// Either a Select subquery or a Struct containing PropertyEQ entries
10325    pub this: Box<Expression>,
10326}
10327
10328/// Pad
10329#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10330#[cfg_attr(feature = "bindings", derive(TS))]
10331pub struct Pad {
10332    pub this: Box<Expression>,
10333    pub expression: Box<Expression>,
10334    #[serde(default)]
10335    pub fill_pattern: Option<Box<Expression>>,
10336    #[serde(default)]
10337    pub is_left: Option<Box<Expression>>,
10338}
10339
10340/// ToChar
10341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10342#[cfg_attr(feature = "bindings", derive(TS))]
10343pub struct ToChar {
10344    pub this: Box<Expression>,
10345    #[serde(default)]
10346    pub format: Option<String>,
10347    #[serde(default)]
10348    pub nlsparam: Option<Box<Expression>>,
10349    #[serde(default)]
10350    pub is_numeric: Option<Box<Expression>>,
10351}
10352
10353/// StringFunc - String type conversion function (BigQuery STRING)
10354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10355#[cfg_attr(feature = "bindings", derive(TS))]
10356pub struct StringFunc {
10357    pub this: Box<Expression>,
10358    #[serde(default)]
10359    pub zone: Option<Box<Expression>>,
10360}
10361
10362/// ToNumber
10363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10364#[cfg_attr(feature = "bindings", derive(TS))]
10365pub struct ToNumber {
10366    pub this: Box<Expression>,
10367    #[serde(default)]
10368    pub format: Option<Box<Expression>>,
10369    #[serde(default)]
10370    pub nlsparam: Option<Box<Expression>>,
10371    #[serde(default)]
10372    pub precision: Option<Box<Expression>>,
10373    #[serde(default)]
10374    pub scale: Option<Box<Expression>>,
10375    #[serde(default)]
10376    pub safe: Option<Box<Expression>>,
10377    #[serde(default)]
10378    pub safe_name: Option<Box<Expression>>,
10379}
10380
10381/// ToDouble
10382#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10383#[cfg_attr(feature = "bindings", derive(TS))]
10384pub struct ToDouble {
10385    pub this: Box<Expression>,
10386    #[serde(default)]
10387    pub format: Option<String>,
10388    #[serde(default)]
10389    pub safe: Option<Box<Expression>>,
10390}
10391
10392/// ToDecfloat
10393#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10394#[cfg_attr(feature = "bindings", derive(TS))]
10395pub struct ToDecfloat {
10396    pub this: Box<Expression>,
10397    #[serde(default)]
10398    pub format: Option<String>,
10399}
10400
10401/// TryToDecfloat
10402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10403#[cfg_attr(feature = "bindings", derive(TS))]
10404pub struct TryToDecfloat {
10405    pub this: Box<Expression>,
10406    #[serde(default)]
10407    pub format: Option<String>,
10408}
10409
10410/// ToFile
10411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10412#[cfg_attr(feature = "bindings", derive(TS))]
10413pub struct ToFile {
10414    pub this: Box<Expression>,
10415    #[serde(default)]
10416    pub path: Option<Box<Expression>>,
10417    #[serde(default)]
10418    pub safe: Option<Box<Expression>>,
10419}
10420
10421/// Columns
10422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10423#[cfg_attr(feature = "bindings", derive(TS))]
10424pub struct Columns {
10425    pub this: Box<Expression>,
10426    #[serde(default)]
10427    pub unpack: Option<Box<Expression>>,
10428}
10429
10430/// ConvertToCharset
10431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10432#[cfg_attr(feature = "bindings", derive(TS))]
10433pub struct ConvertToCharset {
10434    pub this: Box<Expression>,
10435    #[serde(default)]
10436    pub dest: Option<Box<Expression>>,
10437    #[serde(default)]
10438    pub source: Option<Box<Expression>>,
10439}
10440
10441/// ConvertTimezone
10442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10443#[cfg_attr(feature = "bindings", derive(TS))]
10444pub struct ConvertTimezone {
10445    #[serde(default)]
10446    pub source_tz: Option<Box<Expression>>,
10447    #[serde(default)]
10448    pub target_tz: Option<Box<Expression>>,
10449    #[serde(default)]
10450    pub timestamp: Option<Box<Expression>>,
10451    #[serde(default)]
10452    pub options: Vec<Expression>,
10453}
10454
10455/// GenerateSeries
10456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10457#[cfg_attr(feature = "bindings", derive(TS))]
10458pub struct GenerateSeries {
10459    #[serde(default)]
10460    pub start: Option<Box<Expression>>,
10461    #[serde(default)]
10462    pub end: Option<Box<Expression>>,
10463    #[serde(default)]
10464    pub step: Option<Box<Expression>>,
10465    #[serde(default)]
10466    pub is_end_exclusive: Option<Box<Expression>>,
10467}
10468
10469/// AIAgg
10470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10471#[cfg_attr(feature = "bindings", derive(TS))]
10472pub struct AIAgg {
10473    pub this: Box<Expression>,
10474    pub expression: Box<Expression>,
10475}
10476
10477/// AIClassify
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct AIClassify {
10481    pub this: Box<Expression>,
10482    #[serde(default)]
10483    pub categories: Option<Box<Expression>>,
10484    #[serde(default)]
10485    pub config: Option<Box<Expression>>,
10486}
10487
10488/// ArrayAll
10489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10490#[cfg_attr(feature = "bindings", derive(TS))]
10491pub struct ArrayAll {
10492    pub this: Box<Expression>,
10493    pub expression: Box<Expression>,
10494}
10495
10496/// ArrayAny
10497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10498#[cfg_attr(feature = "bindings", derive(TS))]
10499pub struct ArrayAny {
10500    pub this: Box<Expression>,
10501    pub expression: Box<Expression>,
10502}
10503
10504/// ArrayConstructCompact
10505#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10506#[cfg_attr(feature = "bindings", derive(TS))]
10507pub struct ArrayConstructCompact {
10508    #[serde(default)]
10509    pub expressions: Vec<Expression>,
10510}
10511
10512/// StPoint
10513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10514#[cfg_attr(feature = "bindings", derive(TS))]
10515pub struct StPoint {
10516    pub this: Box<Expression>,
10517    pub expression: Box<Expression>,
10518    #[serde(default)]
10519    pub null: Option<Box<Expression>>,
10520}
10521
10522/// StDistance
10523#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10524#[cfg_attr(feature = "bindings", derive(TS))]
10525pub struct StDistance {
10526    pub this: Box<Expression>,
10527    pub expression: Box<Expression>,
10528    #[serde(default)]
10529    pub use_spheroid: Option<Box<Expression>>,
10530}
10531
10532/// StringToArray
10533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10534#[cfg_attr(feature = "bindings", derive(TS))]
10535pub struct StringToArray {
10536    pub this: Box<Expression>,
10537    #[serde(default)]
10538    pub expression: Option<Box<Expression>>,
10539    #[serde(default)]
10540    pub null: Option<Box<Expression>>,
10541}
10542
10543/// ArraySum
10544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10545#[cfg_attr(feature = "bindings", derive(TS))]
10546pub struct ArraySum {
10547    pub this: Box<Expression>,
10548    #[serde(default)]
10549    pub expression: Option<Box<Expression>>,
10550}
10551
10552/// ObjectAgg
10553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10554#[cfg_attr(feature = "bindings", derive(TS))]
10555pub struct ObjectAgg {
10556    pub this: Box<Expression>,
10557    pub expression: Box<Expression>,
10558}
10559
10560/// CastToStrType
10561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10562#[cfg_attr(feature = "bindings", derive(TS))]
10563pub struct CastToStrType {
10564    pub this: Box<Expression>,
10565    #[serde(default)]
10566    pub to: Option<Box<Expression>>,
10567}
10568
10569/// CheckJson
10570#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10571#[cfg_attr(feature = "bindings", derive(TS))]
10572pub struct CheckJson {
10573    pub this: Box<Expression>,
10574}
10575
10576/// CheckXml
10577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10578#[cfg_attr(feature = "bindings", derive(TS))]
10579pub struct CheckXml {
10580    pub this: Box<Expression>,
10581    #[serde(default)]
10582    pub disable_auto_convert: Option<Box<Expression>>,
10583}
10584
10585/// TranslateCharacters
10586#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10587#[cfg_attr(feature = "bindings", derive(TS))]
10588pub struct TranslateCharacters {
10589    pub this: Box<Expression>,
10590    pub expression: Box<Expression>,
10591    #[serde(default)]
10592    pub with_error: Option<Box<Expression>>,
10593}
10594
10595/// CurrentSchemas
10596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10597#[cfg_attr(feature = "bindings", derive(TS))]
10598pub struct CurrentSchemas {
10599    #[serde(default)]
10600    pub this: Option<Box<Expression>>,
10601}
10602
10603/// CurrentDatetime
10604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10605#[cfg_attr(feature = "bindings", derive(TS))]
10606pub struct CurrentDatetime {
10607    #[serde(default)]
10608    pub this: Option<Box<Expression>>,
10609}
10610
10611/// Localtime
10612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10613#[cfg_attr(feature = "bindings", derive(TS))]
10614pub struct Localtime {
10615    #[serde(default)]
10616    pub this: Option<Box<Expression>>,
10617}
10618
10619/// Localtimestamp
10620#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10621#[cfg_attr(feature = "bindings", derive(TS))]
10622pub struct Localtimestamp {
10623    #[serde(default)]
10624    pub this: Option<Box<Expression>>,
10625}
10626
10627/// Systimestamp
10628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10629#[cfg_attr(feature = "bindings", derive(TS))]
10630pub struct Systimestamp {
10631    #[serde(default)]
10632    pub this: Option<Box<Expression>>,
10633}
10634
10635/// CurrentSchema
10636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10637#[cfg_attr(feature = "bindings", derive(TS))]
10638pub struct CurrentSchema {
10639    #[serde(default)]
10640    pub this: Option<Box<Expression>>,
10641}
10642
10643/// CurrentUser
10644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10645#[cfg_attr(feature = "bindings", derive(TS))]
10646pub struct CurrentUser {
10647    #[serde(default)]
10648    pub this: Option<Box<Expression>>,
10649}
10650
10651/// SessionUser - MySQL/PostgreSQL SESSION_USER function
10652#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10653#[cfg_attr(feature = "bindings", derive(TS))]
10654pub struct SessionUser;
10655
10656/// JSONPathRoot - Represents $ in JSON path expressions
10657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10658#[cfg_attr(feature = "bindings", derive(TS))]
10659pub struct JSONPathRoot;
10660
10661/// UtcTime
10662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10663#[cfg_attr(feature = "bindings", derive(TS))]
10664pub struct UtcTime {
10665    #[serde(default)]
10666    pub this: Option<Box<Expression>>,
10667}
10668
10669/// UtcTimestamp
10670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10671#[cfg_attr(feature = "bindings", derive(TS))]
10672pub struct UtcTimestamp {
10673    #[serde(default)]
10674    pub this: Option<Box<Expression>>,
10675}
10676
10677/// TimestampFunc - TIMESTAMP constructor function
10678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10679#[cfg_attr(feature = "bindings", derive(TS))]
10680pub struct TimestampFunc {
10681    #[serde(default)]
10682    pub this: Option<Box<Expression>>,
10683    #[serde(default)]
10684    pub zone: Option<Box<Expression>>,
10685    #[serde(default)]
10686    pub with_tz: Option<bool>,
10687    #[serde(default)]
10688    pub safe: Option<bool>,
10689}
10690
10691/// DateBin
10692#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10693#[cfg_attr(feature = "bindings", derive(TS))]
10694pub struct DateBin {
10695    pub this: Box<Expression>,
10696    pub expression: Box<Expression>,
10697    #[serde(default)]
10698    pub unit: Option<String>,
10699    #[serde(default)]
10700    pub zone: Option<Box<Expression>>,
10701    #[serde(default)]
10702    pub origin: Option<Box<Expression>>,
10703}
10704
10705/// Datetime
10706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10707#[cfg_attr(feature = "bindings", derive(TS))]
10708pub struct Datetime {
10709    pub this: Box<Expression>,
10710    #[serde(default)]
10711    pub expression: Option<Box<Expression>>,
10712}
10713
10714/// DatetimeAdd
10715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10716#[cfg_attr(feature = "bindings", derive(TS))]
10717pub struct DatetimeAdd {
10718    pub this: Box<Expression>,
10719    pub expression: Box<Expression>,
10720    #[serde(default)]
10721    pub unit: Option<String>,
10722}
10723
10724/// DatetimeSub
10725#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10726#[cfg_attr(feature = "bindings", derive(TS))]
10727pub struct DatetimeSub {
10728    pub this: Box<Expression>,
10729    pub expression: Box<Expression>,
10730    #[serde(default)]
10731    pub unit: Option<String>,
10732}
10733
10734/// DatetimeDiff
10735#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10736#[cfg_attr(feature = "bindings", derive(TS))]
10737pub struct DatetimeDiff {
10738    pub this: Box<Expression>,
10739    pub expression: Box<Expression>,
10740    #[serde(default)]
10741    pub unit: Option<String>,
10742}
10743
10744/// DatetimeTrunc
10745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10746#[cfg_attr(feature = "bindings", derive(TS))]
10747pub struct DatetimeTrunc {
10748    pub this: Box<Expression>,
10749    pub unit: String,
10750    #[serde(default)]
10751    pub zone: Option<Box<Expression>>,
10752}
10753
10754/// Dayname
10755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10756#[cfg_attr(feature = "bindings", derive(TS))]
10757pub struct Dayname {
10758    pub this: Box<Expression>,
10759    #[serde(default)]
10760    pub abbreviated: Option<Box<Expression>>,
10761}
10762
10763/// MakeInterval
10764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10765#[cfg_attr(feature = "bindings", derive(TS))]
10766pub struct MakeInterval {
10767    #[serde(default)]
10768    pub year: Option<Box<Expression>>,
10769    #[serde(default)]
10770    pub month: Option<Box<Expression>>,
10771    #[serde(default)]
10772    pub week: Option<Box<Expression>>,
10773    #[serde(default)]
10774    pub day: Option<Box<Expression>>,
10775    #[serde(default)]
10776    pub hour: Option<Box<Expression>>,
10777    #[serde(default)]
10778    pub minute: Option<Box<Expression>>,
10779    #[serde(default)]
10780    pub second: Option<Box<Expression>>,
10781}
10782
10783/// PreviousDay
10784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10785#[cfg_attr(feature = "bindings", derive(TS))]
10786pub struct PreviousDay {
10787    pub this: Box<Expression>,
10788    pub expression: Box<Expression>,
10789}
10790
10791/// Elt
10792#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10793#[cfg_attr(feature = "bindings", derive(TS))]
10794pub struct Elt {
10795    pub this: Box<Expression>,
10796    #[serde(default)]
10797    pub expressions: Vec<Expression>,
10798}
10799
10800/// TimestampAdd
10801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10802#[cfg_attr(feature = "bindings", derive(TS))]
10803pub struct TimestampAdd {
10804    pub this: Box<Expression>,
10805    pub expression: Box<Expression>,
10806    #[serde(default)]
10807    pub unit: Option<String>,
10808}
10809
10810/// TimestampSub
10811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10812#[cfg_attr(feature = "bindings", derive(TS))]
10813pub struct TimestampSub {
10814    pub this: Box<Expression>,
10815    pub expression: Box<Expression>,
10816    #[serde(default)]
10817    pub unit: Option<String>,
10818}
10819
10820/// TimestampDiff
10821#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10822#[cfg_attr(feature = "bindings", derive(TS))]
10823pub struct TimestampDiff {
10824    pub this: Box<Expression>,
10825    pub expression: Box<Expression>,
10826    #[serde(default)]
10827    pub unit: Option<String>,
10828}
10829
10830/// TimeSlice
10831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10832#[cfg_attr(feature = "bindings", derive(TS))]
10833pub struct TimeSlice {
10834    pub this: Box<Expression>,
10835    pub expression: Box<Expression>,
10836    pub unit: String,
10837    #[serde(default)]
10838    pub kind: Option<String>,
10839}
10840
10841/// TimeAdd
10842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10843#[cfg_attr(feature = "bindings", derive(TS))]
10844pub struct TimeAdd {
10845    pub this: Box<Expression>,
10846    pub expression: Box<Expression>,
10847    #[serde(default)]
10848    pub unit: Option<String>,
10849}
10850
10851/// TimeSub
10852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10853#[cfg_attr(feature = "bindings", derive(TS))]
10854pub struct TimeSub {
10855    pub this: Box<Expression>,
10856    pub expression: Box<Expression>,
10857    #[serde(default)]
10858    pub unit: Option<String>,
10859}
10860
10861/// TimeDiff
10862#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10863#[cfg_attr(feature = "bindings", derive(TS))]
10864pub struct TimeDiff {
10865    pub this: Box<Expression>,
10866    pub expression: Box<Expression>,
10867    #[serde(default)]
10868    pub unit: Option<String>,
10869}
10870
10871/// TimeTrunc
10872#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10873#[cfg_attr(feature = "bindings", derive(TS))]
10874pub struct TimeTrunc {
10875    pub this: Box<Expression>,
10876    pub unit: String,
10877    #[serde(default)]
10878    pub zone: Option<Box<Expression>>,
10879}
10880
10881/// DateFromParts
10882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10883#[cfg_attr(feature = "bindings", derive(TS))]
10884pub struct DateFromParts {
10885    #[serde(default)]
10886    pub year: Option<Box<Expression>>,
10887    #[serde(default)]
10888    pub month: Option<Box<Expression>>,
10889    #[serde(default)]
10890    pub day: Option<Box<Expression>>,
10891    #[serde(default)]
10892    pub allow_overflow: Option<Box<Expression>>,
10893}
10894
10895/// TimeFromParts
10896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10897#[cfg_attr(feature = "bindings", derive(TS))]
10898pub struct TimeFromParts {
10899    #[serde(default)]
10900    pub hour: Option<Box<Expression>>,
10901    #[serde(default)]
10902    pub min: Option<Box<Expression>>,
10903    #[serde(default)]
10904    pub sec: Option<Box<Expression>>,
10905    #[serde(default)]
10906    pub nano: Option<Box<Expression>>,
10907    #[serde(default)]
10908    pub fractions: Option<Box<Expression>>,
10909    #[serde(default)]
10910    pub precision: Option<i64>,
10911}
10912
10913/// DecodeCase
10914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10915#[cfg_attr(feature = "bindings", derive(TS))]
10916pub struct DecodeCase {
10917    #[serde(default)]
10918    pub expressions: Vec<Expression>,
10919}
10920
10921/// Decrypt
10922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10923#[cfg_attr(feature = "bindings", derive(TS))]
10924pub struct Decrypt {
10925    pub this: Box<Expression>,
10926    #[serde(default)]
10927    pub passphrase: Option<Box<Expression>>,
10928    #[serde(default)]
10929    pub aad: Option<Box<Expression>>,
10930    #[serde(default)]
10931    pub encryption_method: Option<Box<Expression>>,
10932    #[serde(default)]
10933    pub safe: Option<Box<Expression>>,
10934}
10935
10936/// DecryptRaw
10937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10938#[cfg_attr(feature = "bindings", derive(TS))]
10939pub struct DecryptRaw {
10940    pub this: Box<Expression>,
10941    #[serde(default)]
10942    pub key: Option<Box<Expression>>,
10943    #[serde(default)]
10944    pub iv: Option<Box<Expression>>,
10945    #[serde(default)]
10946    pub aad: Option<Box<Expression>>,
10947    #[serde(default)]
10948    pub encryption_method: Option<Box<Expression>>,
10949    #[serde(default)]
10950    pub aead: Option<Box<Expression>>,
10951    #[serde(default)]
10952    pub safe: Option<Box<Expression>>,
10953}
10954
10955/// Encode
10956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10957#[cfg_attr(feature = "bindings", derive(TS))]
10958pub struct Encode {
10959    pub this: Box<Expression>,
10960    #[serde(default)]
10961    pub charset: Option<Box<Expression>>,
10962}
10963
10964/// Encrypt
10965#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10966#[cfg_attr(feature = "bindings", derive(TS))]
10967pub struct Encrypt {
10968    pub this: Box<Expression>,
10969    #[serde(default)]
10970    pub passphrase: Option<Box<Expression>>,
10971    #[serde(default)]
10972    pub aad: Option<Box<Expression>>,
10973    #[serde(default)]
10974    pub encryption_method: Option<Box<Expression>>,
10975}
10976
10977/// EncryptRaw
10978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10979#[cfg_attr(feature = "bindings", derive(TS))]
10980pub struct EncryptRaw {
10981    pub this: Box<Expression>,
10982    #[serde(default)]
10983    pub key: Option<Box<Expression>>,
10984    #[serde(default)]
10985    pub iv: Option<Box<Expression>>,
10986    #[serde(default)]
10987    pub aad: Option<Box<Expression>>,
10988    #[serde(default)]
10989    pub encryption_method: Option<Box<Expression>>,
10990}
10991
10992/// EqualNull
10993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10994#[cfg_attr(feature = "bindings", derive(TS))]
10995pub struct EqualNull {
10996    pub this: Box<Expression>,
10997    pub expression: Box<Expression>,
10998}
10999
11000/// ToBinary
11001#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11002#[cfg_attr(feature = "bindings", derive(TS))]
11003pub struct ToBinary {
11004    pub this: Box<Expression>,
11005    #[serde(default)]
11006    pub format: Option<String>,
11007    #[serde(default)]
11008    pub safe: Option<Box<Expression>>,
11009}
11010
11011/// Base64DecodeBinary
11012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11013#[cfg_attr(feature = "bindings", derive(TS))]
11014pub struct Base64DecodeBinary {
11015    pub this: Box<Expression>,
11016    #[serde(default)]
11017    pub alphabet: Option<Box<Expression>>,
11018}
11019
11020/// Base64DecodeString
11021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11022#[cfg_attr(feature = "bindings", derive(TS))]
11023pub struct Base64DecodeString {
11024    pub this: Box<Expression>,
11025    #[serde(default)]
11026    pub alphabet: Option<Box<Expression>>,
11027}
11028
11029/// Base64Encode
11030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11031#[cfg_attr(feature = "bindings", derive(TS))]
11032pub struct Base64Encode {
11033    pub this: Box<Expression>,
11034    #[serde(default)]
11035    pub max_line_length: Option<Box<Expression>>,
11036    #[serde(default)]
11037    pub alphabet: Option<Box<Expression>>,
11038}
11039
11040/// TryBase64DecodeBinary
11041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11042#[cfg_attr(feature = "bindings", derive(TS))]
11043pub struct TryBase64DecodeBinary {
11044    pub this: Box<Expression>,
11045    #[serde(default)]
11046    pub alphabet: Option<Box<Expression>>,
11047}
11048
11049/// TryBase64DecodeString
11050#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11051#[cfg_attr(feature = "bindings", derive(TS))]
11052pub struct TryBase64DecodeString {
11053    pub this: Box<Expression>,
11054    #[serde(default)]
11055    pub alphabet: Option<Box<Expression>>,
11056}
11057
11058/// GapFill
11059#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11060#[cfg_attr(feature = "bindings", derive(TS))]
11061pub struct GapFill {
11062    pub this: Box<Expression>,
11063    #[serde(default)]
11064    pub ts_column: Option<Box<Expression>>,
11065    #[serde(default)]
11066    pub bucket_width: Option<Box<Expression>>,
11067    #[serde(default)]
11068    pub partitioning_columns: Option<Box<Expression>>,
11069    #[serde(default)]
11070    pub value_columns: Option<Box<Expression>>,
11071    #[serde(default)]
11072    pub origin: Option<Box<Expression>>,
11073    #[serde(default)]
11074    pub ignore_nulls: Option<Box<Expression>>,
11075}
11076
11077/// GenerateDateArray
11078#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11079#[cfg_attr(feature = "bindings", derive(TS))]
11080pub struct GenerateDateArray {
11081    #[serde(default)]
11082    pub start: Option<Box<Expression>>,
11083    #[serde(default)]
11084    pub end: Option<Box<Expression>>,
11085    #[serde(default)]
11086    pub step: Option<Box<Expression>>,
11087}
11088
11089/// GenerateTimestampArray
11090#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11091#[cfg_attr(feature = "bindings", derive(TS))]
11092pub struct GenerateTimestampArray {
11093    #[serde(default)]
11094    pub start: Option<Box<Expression>>,
11095    #[serde(default)]
11096    pub end: Option<Box<Expression>>,
11097    #[serde(default)]
11098    pub step: Option<Box<Expression>>,
11099}
11100
11101/// GetExtract
11102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11103#[cfg_attr(feature = "bindings", derive(TS))]
11104pub struct GetExtract {
11105    pub this: Box<Expression>,
11106    pub expression: Box<Expression>,
11107}
11108
11109/// Getbit
11110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11111#[cfg_attr(feature = "bindings", derive(TS))]
11112pub struct Getbit {
11113    pub this: Box<Expression>,
11114    pub expression: Box<Expression>,
11115    #[serde(default)]
11116    pub zero_is_msb: Option<Box<Expression>>,
11117}
11118
11119/// OverflowTruncateBehavior
11120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11121#[cfg_attr(feature = "bindings", derive(TS))]
11122pub struct OverflowTruncateBehavior {
11123    #[serde(default)]
11124    pub this: Option<Box<Expression>>,
11125    #[serde(default)]
11126    pub with_count: Option<Box<Expression>>,
11127}
11128
11129/// HexEncode
11130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11131#[cfg_attr(feature = "bindings", derive(TS))]
11132pub struct HexEncode {
11133    pub this: Box<Expression>,
11134    #[serde(default)]
11135    pub case: Option<Box<Expression>>,
11136}
11137
11138/// Compress
11139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11140#[cfg_attr(feature = "bindings", derive(TS))]
11141pub struct Compress {
11142    pub this: Box<Expression>,
11143    #[serde(default)]
11144    pub method: Option<String>,
11145}
11146
11147/// DecompressBinary
11148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11149#[cfg_attr(feature = "bindings", derive(TS))]
11150pub struct DecompressBinary {
11151    pub this: Box<Expression>,
11152    pub method: String,
11153}
11154
11155/// DecompressString
11156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11157#[cfg_attr(feature = "bindings", derive(TS))]
11158pub struct DecompressString {
11159    pub this: Box<Expression>,
11160    pub method: String,
11161}
11162
11163/// Xor
11164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11165#[cfg_attr(feature = "bindings", derive(TS))]
11166pub struct Xor {
11167    #[serde(default)]
11168    pub this: Option<Box<Expression>>,
11169    #[serde(default)]
11170    pub expression: Option<Box<Expression>>,
11171    #[serde(default)]
11172    pub expressions: Vec<Expression>,
11173}
11174
11175/// Nullif
11176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11177#[cfg_attr(feature = "bindings", derive(TS))]
11178pub struct Nullif {
11179    pub this: Box<Expression>,
11180    pub expression: Box<Expression>,
11181}
11182
11183/// JSON
11184#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11185#[cfg_attr(feature = "bindings", derive(TS))]
11186pub struct JSON {
11187    #[serde(default)]
11188    pub this: Option<Box<Expression>>,
11189    #[serde(default)]
11190    pub with_: Option<Box<Expression>>,
11191    #[serde(default)]
11192    pub unique: bool,
11193}
11194
11195/// JSONPath
11196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11197#[cfg_attr(feature = "bindings", derive(TS))]
11198pub struct JSONPath {
11199    #[serde(default)]
11200    pub expressions: Vec<Expression>,
11201    #[serde(default)]
11202    pub escape: Option<Box<Expression>>,
11203}
11204
11205/// JSONPathFilter
11206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11207#[cfg_attr(feature = "bindings", derive(TS))]
11208pub struct JSONPathFilter {
11209    pub this: Box<Expression>,
11210}
11211
11212/// JSONPathKey
11213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11214#[cfg_attr(feature = "bindings", derive(TS))]
11215pub struct JSONPathKey {
11216    pub this: Box<Expression>,
11217}
11218
11219/// JSONPathRecursive
11220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11221#[cfg_attr(feature = "bindings", derive(TS))]
11222pub struct JSONPathRecursive {
11223    #[serde(default)]
11224    pub this: Option<Box<Expression>>,
11225}
11226
11227/// JSONPathScript
11228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11229#[cfg_attr(feature = "bindings", derive(TS))]
11230pub struct JSONPathScript {
11231    pub this: Box<Expression>,
11232}
11233
11234/// JSONPathSlice
11235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11236#[cfg_attr(feature = "bindings", derive(TS))]
11237pub struct JSONPathSlice {
11238    #[serde(default)]
11239    pub start: Option<Box<Expression>>,
11240    #[serde(default)]
11241    pub end: Option<Box<Expression>>,
11242    #[serde(default)]
11243    pub step: Option<Box<Expression>>,
11244}
11245
11246/// JSONPathSelector
11247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11248#[cfg_attr(feature = "bindings", derive(TS))]
11249pub struct JSONPathSelector {
11250    pub this: Box<Expression>,
11251}
11252
11253/// JSONPathSubscript
11254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11255#[cfg_attr(feature = "bindings", derive(TS))]
11256pub struct JSONPathSubscript {
11257    pub this: Box<Expression>,
11258}
11259
11260/// JSONPathUnion
11261#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11262#[cfg_attr(feature = "bindings", derive(TS))]
11263pub struct JSONPathUnion {
11264    #[serde(default)]
11265    pub expressions: Vec<Expression>,
11266}
11267
11268/// Format
11269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11270#[cfg_attr(feature = "bindings", derive(TS))]
11271pub struct Format {
11272    pub this: Box<Expression>,
11273    #[serde(default)]
11274    pub expressions: Vec<Expression>,
11275}
11276
11277/// JSONKeys
11278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11279#[cfg_attr(feature = "bindings", derive(TS))]
11280pub struct JSONKeys {
11281    pub this: Box<Expression>,
11282    #[serde(default)]
11283    pub expression: Option<Box<Expression>>,
11284    #[serde(default)]
11285    pub expressions: Vec<Expression>,
11286}
11287
11288/// JSONKeyValue
11289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11290#[cfg_attr(feature = "bindings", derive(TS))]
11291pub struct JSONKeyValue {
11292    pub this: Box<Expression>,
11293    pub expression: Box<Expression>,
11294}
11295
11296/// JSONKeysAtDepth
11297#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11298#[cfg_attr(feature = "bindings", derive(TS))]
11299pub struct JSONKeysAtDepth {
11300    pub this: Box<Expression>,
11301    #[serde(default)]
11302    pub expression: Option<Box<Expression>>,
11303    #[serde(default)]
11304    pub mode: Option<Box<Expression>>,
11305}
11306
11307/// JSONObject
11308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11309#[cfg_attr(feature = "bindings", derive(TS))]
11310pub struct JSONObject {
11311    #[serde(default)]
11312    pub expressions: Vec<Expression>,
11313    #[serde(default)]
11314    pub null_handling: Option<Box<Expression>>,
11315    #[serde(default)]
11316    pub unique_keys: Option<Box<Expression>>,
11317    #[serde(default)]
11318    pub return_type: Option<Box<Expression>>,
11319    #[serde(default)]
11320    pub encoding: Option<Box<Expression>>,
11321}
11322
11323/// JSONObjectAgg
11324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11325#[cfg_attr(feature = "bindings", derive(TS))]
11326pub struct JSONObjectAgg {
11327    #[serde(default)]
11328    pub expressions: Vec<Expression>,
11329    #[serde(default)]
11330    pub null_handling: Option<Box<Expression>>,
11331    #[serde(default)]
11332    pub unique_keys: Option<Box<Expression>>,
11333    #[serde(default)]
11334    pub return_type: Option<Box<Expression>>,
11335    #[serde(default)]
11336    pub encoding: Option<Box<Expression>>,
11337}
11338
11339/// JSONBObjectAgg
11340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11341#[cfg_attr(feature = "bindings", derive(TS))]
11342pub struct JSONBObjectAgg {
11343    pub this: Box<Expression>,
11344    pub expression: Box<Expression>,
11345}
11346
11347/// JSONArray
11348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11349#[cfg_attr(feature = "bindings", derive(TS))]
11350pub struct JSONArray {
11351    #[serde(default)]
11352    pub expressions: Vec<Expression>,
11353    #[serde(default)]
11354    pub null_handling: Option<Box<Expression>>,
11355    #[serde(default)]
11356    pub return_type: Option<Box<Expression>>,
11357    #[serde(default)]
11358    pub strict: Option<Box<Expression>>,
11359}
11360
11361/// JSONArrayAgg
11362#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11363#[cfg_attr(feature = "bindings", derive(TS))]
11364pub struct JSONArrayAgg {
11365    pub this: Box<Expression>,
11366    #[serde(default)]
11367    pub order: Option<Box<Expression>>,
11368    #[serde(default)]
11369    pub null_handling: Option<Box<Expression>>,
11370    #[serde(default)]
11371    pub return_type: Option<Box<Expression>>,
11372    #[serde(default)]
11373    pub strict: Option<Box<Expression>>,
11374}
11375
11376/// JSONExists
11377#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11378#[cfg_attr(feature = "bindings", derive(TS))]
11379pub struct JSONExists {
11380    pub this: Box<Expression>,
11381    #[serde(default)]
11382    pub path: Option<Box<Expression>>,
11383    #[serde(default)]
11384    pub passing: Option<Box<Expression>>,
11385    #[serde(default)]
11386    pub on_condition: Option<Box<Expression>>,
11387    #[serde(default)]
11388    pub from_dcolonqmark: Option<Box<Expression>>,
11389}
11390
11391/// JSONColumnDef
11392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11393#[cfg_attr(feature = "bindings", derive(TS))]
11394pub struct JSONColumnDef {
11395    #[serde(default)]
11396    pub this: Option<Box<Expression>>,
11397    #[serde(default)]
11398    pub kind: Option<String>,
11399    #[serde(default)]
11400    pub path: Option<Box<Expression>>,
11401    #[serde(default)]
11402    pub nested_schema: Option<Box<Expression>>,
11403    #[serde(default)]
11404    pub ordinality: Option<Box<Expression>>,
11405}
11406
11407/// JSONSchema
11408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11409#[cfg_attr(feature = "bindings", derive(TS))]
11410pub struct JSONSchema {
11411    #[serde(default)]
11412    pub expressions: Vec<Expression>,
11413}
11414
11415/// JSONSet
11416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11417#[cfg_attr(feature = "bindings", derive(TS))]
11418pub struct JSONSet {
11419    pub this: Box<Expression>,
11420    #[serde(default)]
11421    pub expressions: Vec<Expression>,
11422}
11423
11424/// JSONStripNulls
11425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11426#[cfg_attr(feature = "bindings", derive(TS))]
11427pub struct JSONStripNulls {
11428    pub this: Box<Expression>,
11429    #[serde(default)]
11430    pub expression: Option<Box<Expression>>,
11431    #[serde(default)]
11432    pub include_arrays: Option<Box<Expression>>,
11433    #[serde(default)]
11434    pub remove_empty: Option<Box<Expression>>,
11435}
11436
11437/// JSONValue
11438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11439#[cfg_attr(feature = "bindings", derive(TS))]
11440pub struct JSONValue {
11441    pub this: Box<Expression>,
11442    #[serde(default)]
11443    pub path: Option<Box<Expression>>,
11444    #[serde(default)]
11445    pub returning: Option<Box<Expression>>,
11446    #[serde(default)]
11447    pub on_condition: Option<Box<Expression>>,
11448}
11449
11450/// JSONValueArray
11451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11452#[cfg_attr(feature = "bindings", derive(TS))]
11453pub struct JSONValueArray {
11454    pub this: Box<Expression>,
11455    #[serde(default)]
11456    pub expression: Option<Box<Expression>>,
11457}
11458
11459/// JSONRemove
11460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11461#[cfg_attr(feature = "bindings", derive(TS))]
11462pub struct JSONRemove {
11463    pub this: Box<Expression>,
11464    #[serde(default)]
11465    pub expressions: Vec<Expression>,
11466}
11467
11468/// JSONTable
11469#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11470#[cfg_attr(feature = "bindings", derive(TS))]
11471pub struct JSONTable {
11472    pub this: Box<Expression>,
11473    #[serde(default)]
11474    pub schema: Option<Box<Expression>>,
11475    #[serde(default)]
11476    pub path: Option<Box<Expression>>,
11477    #[serde(default)]
11478    pub error_handling: Option<Box<Expression>>,
11479    #[serde(default)]
11480    pub empty_handling: Option<Box<Expression>>,
11481}
11482
11483/// JSONType
11484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11485#[cfg_attr(feature = "bindings", derive(TS))]
11486pub struct JSONType {
11487    pub this: Box<Expression>,
11488    #[serde(default)]
11489    pub expression: Option<Box<Expression>>,
11490}
11491
11492/// ObjectInsert
11493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11494#[cfg_attr(feature = "bindings", derive(TS))]
11495pub struct ObjectInsert {
11496    pub this: Box<Expression>,
11497    #[serde(default)]
11498    pub key: Option<Box<Expression>>,
11499    #[serde(default)]
11500    pub value: Option<Box<Expression>>,
11501    #[serde(default)]
11502    pub update_flag: Option<Box<Expression>>,
11503}
11504
11505/// OpenJSONColumnDef
11506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11507#[cfg_attr(feature = "bindings", derive(TS))]
11508pub struct OpenJSONColumnDef {
11509    pub this: Box<Expression>,
11510    pub kind: String,
11511    #[serde(default)]
11512    pub path: Option<Box<Expression>>,
11513    #[serde(default)]
11514    pub as_json: Option<Box<Expression>>,
11515    /// The parsed data type for proper generation
11516    #[serde(default, skip_serializing_if = "Option::is_none")]
11517    pub data_type: Option<DataType>,
11518}
11519
11520/// OpenJSON
11521#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11522#[cfg_attr(feature = "bindings", derive(TS))]
11523pub struct OpenJSON {
11524    pub this: Box<Expression>,
11525    #[serde(default)]
11526    pub path: Option<Box<Expression>>,
11527    #[serde(default)]
11528    pub expressions: Vec<Expression>,
11529}
11530
11531/// JSONBExists
11532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11533#[cfg_attr(feature = "bindings", derive(TS))]
11534pub struct JSONBExists {
11535    pub this: Box<Expression>,
11536    #[serde(default)]
11537    pub path: Option<Box<Expression>>,
11538}
11539
11540/// JSONCast
11541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11542#[cfg_attr(feature = "bindings", derive(TS))]
11543pub struct JSONCast {
11544    pub this: Box<Expression>,
11545    pub to: DataType,
11546}
11547
11548/// JSONExtract
11549#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11550#[cfg_attr(feature = "bindings", derive(TS))]
11551pub struct JSONExtract {
11552    pub this: Box<Expression>,
11553    pub expression: Box<Expression>,
11554    #[serde(default)]
11555    pub only_json_types: Option<Box<Expression>>,
11556    #[serde(default)]
11557    pub expressions: Vec<Expression>,
11558    #[serde(default)]
11559    pub variant_extract: Option<Box<Expression>>,
11560    #[serde(default)]
11561    pub json_query: Option<Box<Expression>>,
11562    #[serde(default)]
11563    pub option: Option<Box<Expression>>,
11564    #[serde(default)]
11565    pub quote: Option<Box<Expression>>,
11566    #[serde(default)]
11567    pub on_condition: Option<Box<Expression>>,
11568    #[serde(default)]
11569    pub requires_json: Option<Box<Expression>>,
11570}
11571
11572/// JSONExtractQuote
11573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11574#[cfg_attr(feature = "bindings", derive(TS))]
11575pub struct JSONExtractQuote {
11576    #[serde(default)]
11577    pub option: Option<Box<Expression>>,
11578    #[serde(default)]
11579    pub scalar: Option<Box<Expression>>,
11580}
11581
11582/// JSONExtractArray
11583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11584#[cfg_attr(feature = "bindings", derive(TS))]
11585pub struct JSONExtractArray {
11586    pub this: Box<Expression>,
11587    #[serde(default)]
11588    pub expression: Option<Box<Expression>>,
11589}
11590
11591/// JSONExtractScalar
11592#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11593#[cfg_attr(feature = "bindings", derive(TS))]
11594pub struct JSONExtractScalar {
11595    pub this: Box<Expression>,
11596    pub expression: Box<Expression>,
11597    #[serde(default)]
11598    pub only_json_types: Option<Box<Expression>>,
11599    #[serde(default)]
11600    pub expressions: Vec<Expression>,
11601    #[serde(default)]
11602    pub json_type: Option<Box<Expression>>,
11603    #[serde(default)]
11604    pub scalar_only: Option<Box<Expression>>,
11605}
11606
11607/// JSONBExtractScalar
11608#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11609#[cfg_attr(feature = "bindings", derive(TS))]
11610pub struct JSONBExtractScalar {
11611    pub this: Box<Expression>,
11612    pub expression: Box<Expression>,
11613    #[serde(default)]
11614    pub json_type: Option<Box<Expression>>,
11615}
11616
11617/// JSONFormat
11618#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11619#[cfg_attr(feature = "bindings", derive(TS))]
11620pub struct JSONFormat {
11621    #[serde(default)]
11622    pub this: Option<Box<Expression>>,
11623    #[serde(default)]
11624    pub options: Vec<Expression>,
11625    #[serde(default)]
11626    pub is_json: Option<Box<Expression>>,
11627    #[serde(default)]
11628    pub to_json: Option<Box<Expression>>,
11629}
11630
11631/// JSONArrayAppend
11632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11633#[cfg_attr(feature = "bindings", derive(TS))]
11634pub struct JSONArrayAppend {
11635    pub this: Box<Expression>,
11636    #[serde(default)]
11637    pub expressions: Vec<Expression>,
11638}
11639
11640/// JSONArrayContains
11641#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11642#[cfg_attr(feature = "bindings", derive(TS))]
11643pub struct JSONArrayContains {
11644    pub this: Box<Expression>,
11645    pub expression: Box<Expression>,
11646    #[serde(default)]
11647    pub json_type: Option<Box<Expression>>,
11648}
11649
11650/// JSONArrayInsert
11651#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11652#[cfg_attr(feature = "bindings", derive(TS))]
11653pub struct JSONArrayInsert {
11654    pub this: Box<Expression>,
11655    #[serde(default)]
11656    pub expressions: Vec<Expression>,
11657}
11658
11659/// ParseJSON
11660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11661#[cfg_attr(feature = "bindings", derive(TS))]
11662pub struct ParseJSON {
11663    pub this: Box<Expression>,
11664    #[serde(default)]
11665    pub expression: Option<Box<Expression>>,
11666    #[serde(default)]
11667    pub safe: Option<Box<Expression>>,
11668}
11669
11670/// ParseUrl
11671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11672#[cfg_attr(feature = "bindings", derive(TS))]
11673pub struct ParseUrl {
11674    pub this: Box<Expression>,
11675    #[serde(default)]
11676    pub part_to_extract: Option<Box<Expression>>,
11677    #[serde(default)]
11678    pub key: Option<Box<Expression>>,
11679    #[serde(default)]
11680    pub permissive: Option<Box<Expression>>,
11681}
11682
11683/// ParseIp
11684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11685#[cfg_attr(feature = "bindings", derive(TS))]
11686pub struct ParseIp {
11687    pub this: Box<Expression>,
11688    #[serde(default)]
11689    pub type_: Option<Box<Expression>>,
11690    #[serde(default)]
11691    pub permissive: Option<Box<Expression>>,
11692}
11693
11694/// ParseTime
11695#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11696#[cfg_attr(feature = "bindings", derive(TS))]
11697pub struct ParseTime {
11698    pub this: Box<Expression>,
11699    pub format: String,
11700}
11701
11702/// ParseDatetime
11703#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11704#[cfg_attr(feature = "bindings", derive(TS))]
11705pub struct ParseDatetime {
11706    pub this: Box<Expression>,
11707    #[serde(default)]
11708    pub format: Option<String>,
11709    #[serde(default)]
11710    pub zone: Option<Box<Expression>>,
11711}
11712
11713/// Map
11714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11715#[cfg_attr(feature = "bindings", derive(TS))]
11716pub struct Map {
11717    #[serde(default)]
11718    pub keys: Vec<Expression>,
11719    #[serde(default)]
11720    pub values: Vec<Expression>,
11721}
11722
11723/// MapCat
11724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11725#[cfg_attr(feature = "bindings", derive(TS))]
11726pub struct MapCat {
11727    pub this: Box<Expression>,
11728    pub expression: Box<Expression>,
11729}
11730
11731/// MapDelete
11732#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11733#[cfg_attr(feature = "bindings", derive(TS))]
11734pub struct MapDelete {
11735    pub this: Box<Expression>,
11736    #[serde(default)]
11737    pub expressions: Vec<Expression>,
11738}
11739
11740/// MapInsert
11741#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11742#[cfg_attr(feature = "bindings", derive(TS))]
11743pub struct MapInsert {
11744    pub this: Box<Expression>,
11745    #[serde(default)]
11746    pub key: Option<Box<Expression>>,
11747    #[serde(default)]
11748    pub value: Option<Box<Expression>>,
11749    #[serde(default)]
11750    pub update_flag: Option<Box<Expression>>,
11751}
11752
11753/// MapPick
11754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11755#[cfg_attr(feature = "bindings", derive(TS))]
11756pub struct MapPick {
11757    pub this: Box<Expression>,
11758    #[serde(default)]
11759    pub expressions: Vec<Expression>,
11760}
11761
11762/// ScopeResolution
11763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11764#[cfg_attr(feature = "bindings", derive(TS))]
11765pub struct ScopeResolution {
11766    #[serde(default)]
11767    pub this: Option<Box<Expression>>,
11768    pub expression: Box<Expression>,
11769}
11770
11771/// Slice
11772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11773#[cfg_attr(feature = "bindings", derive(TS))]
11774pub struct Slice {
11775    #[serde(default)]
11776    pub this: Option<Box<Expression>>,
11777    #[serde(default)]
11778    pub expression: Option<Box<Expression>>,
11779    #[serde(default)]
11780    pub step: Option<Box<Expression>>,
11781}
11782
11783/// VarMap
11784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11785#[cfg_attr(feature = "bindings", derive(TS))]
11786pub struct VarMap {
11787    #[serde(default)]
11788    pub keys: Vec<Expression>,
11789    #[serde(default)]
11790    pub values: Vec<Expression>,
11791}
11792
11793/// MatchAgainst
11794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11795#[cfg_attr(feature = "bindings", derive(TS))]
11796pub struct MatchAgainst {
11797    pub this: Box<Expression>,
11798    #[serde(default)]
11799    pub expressions: Vec<Expression>,
11800    #[serde(default)]
11801    pub modifier: Option<Box<Expression>>,
11802}
11803
11804/// MD5Digest
11805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11806#[cfg_attr(feature = "bindings", derive(TS))]
11807pub struct MD5Digest {
11808    pub this: Box<Expression>,
11809    #[serde(default)]
11810    pub expressions: Vec<Expression>,
11811}
11812
11813/// Monthname
11814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11815#[cfg_attr(feature = "bindings", derive(TS))]
11816pub struct Monthname {
11817    pub this: Box<Expression>,
11818    #[serde(default)]
11819    pub abbreviated: Option<Box<Expression>>,
11820}
11821
11822/// Ntile
11823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11824#[cfg_attr(feature = "bindings", derive(TS))]
11825pub struct Ntile {
11826    #[serde(default)]
11827    pub this: Option<Box<Expression>>,
11828}
11829
11830/// Normalize
11831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11832#[cfg_attr(feature = "bindings", derive(TS))]
11833pub struct Normalize {
11834    pub this: Box<Expression>,
11835    #[serde(default)]
11836    pub form: Option<Box<Expression>>,
11837    #[serde(default)]
11838    pub is_casefold: Option<Box<Expression>>,
11839}
11840
11841/// Normal
11842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11843#[cfg_attr(feature = "bindings", derive(TS))]
11844pub struct Normal {
11845    pub this: Box<Expression>,
11846    #[serde(default)]
11847    pub stddev: Option<Box<Expression>>,
11848    #[serde(default)]
11849    pub gen: Option<Box<Expression>>,
11850}
11851
11852/// Predict
11853#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11854#[cfg_attr(feature = "bindings", derive(TS))]
11855pub struct Predict {
11856    pub this: Box<Expression>,
11857    pub expression: Box<Expression>,
11858    #[serde(default)]
11859    pub params_struct: Option<Box<Expression>>,
11860}
11861
11862/// MLTranslate
11863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11864#[cfg_attr(feature = "bindings", derive(TS))]
11865pub struct MLTranslate {
11866    pub this: Box<Expression>,
11867    pub expression: Box<Expression>,
11868    #[serde(default)]
11869    pub params_struct: Option<Box<Expression>>,
11870}
11871
11872/// FeaturesAtTime
11873#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11874#[cfg_attr(feature = "bindings", derive(TS))]
11875pub struct FeaturesAtTime {
11876    pub this: Box<Expression>,
11877    #[serde(default)]
11878    pub time: Option<Box<Expression>>,
11879    #[serde(default)]
11880    pub num_rows: Option<Box<Expression>>,
11881    #[serde(default)]
11882    pub ignore_feature_nulls: Option<Box<Expression>>,
11883}
11884
11885/// GenerateEmbedding
11886#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11887#[cfg_attr(feature = "bindings", derive(TS))]
11888pub struct GenerateEmbedding {
11889    pub this: Box<Expression>,
11890    pub expression: Box<Expression>,
11891    #[serde(default)]
11892    pub params_struct: Option<Box<Expression>>,
11893    #[serde(default)]
11894    pub is_text: Option<Box<Expression>>,
11895}
11896
11897/// MLForecast
11898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11899#[cfg_attr(feature = "bindings", derive(TS))]
11900pub struct MLForecast {
11901    pub this: Box<Expression>,
11902    #[serde(default)]
11903    pub expression: Option<Box<Expression>>,
11904    #[serde(default)]
11905    pub params_struct: Option<Box<Expression>>,
11906}
11907
11908/// ModelAttribute
11909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11910#[cfg_attr(feature = "bindings", derive(TS))]
11911pub struct ModelAttribute {
11912    pub this: Box<Expression>,
11913    pub expression: Box<Expression>,
11914}
11915
11916/// VectorSearch
11917#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11918#[cfg_attr(feature = "bindings", derive(TS))]
11919pub struct VectorSearch {
11920    pub this: Box<Expression>,
11921    #[serde(default)]
11922    pub column_to_search: Option<Box<Expression>>,
11923    #[serde(default)]
11924    pub query_table: Option<Box<Expression>>,
11925    #[serde(default)]
11926    pub query_column_to_search: Option<Box<Expression>>,
11927    #[serde(default)]
11928    pub top_k: Option<Box<Expression>>,
11929    #[serde(default)]
11930    pub distance_type: Option<Box<Expression>>,
11931    #[serde(default)]
11932    pub options: Vec<Expression>,
11933}
11934
11935/// Quantile
11936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11937#[cfg_attr(feature = "bindings", derive(TS))]
11938pub struct Quantile {
11939    pub this: Box<Expression>,
11940    #[serde(default)]
11941    pub quantile: Option<Box<Expression>>,
11942}
11943
11944/// ApproxQuantile
11945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11946#[cfg_attr(feature = "bindings", derive(TS))]
11947pub struct ApproxQuantile {
11948    pub this: Box<Expression>,
11949    #[serde(default)]
11950    pub quantile: Option<Box<Expression>>,
11951    #[serde(default)]
11952    pub accuracy: Option<Box<Expression>>,
11953    #[serde(default)]
11954    pub weight: Option<Box<Expression>>,
11955    #[serde(default)]
11956    pub error_tolerance: Option<Box<Expression>>,
11957}
11958
11959/// ApproxPercentileEstimate
11960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11961#[cfg_attr(feature = "bindings", derive(TS))]
11962pub struct ApproxPercentileEstimate {
11963    pub this: Box<Expression>,
11964    #[serde(default)]
11965    pub percentile: Option<Box<Expression>>,
11966}
11967
11968/// Randn
11969#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11970#[cfg_attr(feature = "bindings", derive(TS))]
11971pub struct Randn {
11972    #[serde(default)]
11973    pub this: Option<Box<Expression>>,
11974}
11975
11976/// Randstr
11977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11978#[cfg_attr(feature = "bindings", derive(TS))]
11979pub struct Randstr {
11980    pub this: Box<Expression>,
11981    #[serde(default)]
11982    pub generator: Option<Box<Expression>>,
11983}
11984
11985/// RangeN
11986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11987#[cfg_attr(feature = "bindings", derive(TS))]
11988pub struct RangeN {
11989    pub this: Box<Expression>,
11990    #[serde(default)]
11991    pub expressions: Vec<Expression>,
11992    #[serde(default)]
11993    pub each: Option<Box<Expression>>,
11994}
11995
11996/// RangeBucket
11997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11998#[cfg_attr(feature = "bindings", derive(TS))]
11999pub struct RangeBucket {
12000    pub this: Box<Expression>,
12001    pub expression: Box<Expression>,
12002}
12003
12004/// ReadCSV
12005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12006#[cfg_attr(feature = "bindings", derive(TS))]
12007pub struct ReadCSV {
12008    pub this: Box<Expression>,
12009    #[serde(default)]
12010    pub expressions: Vec<Expression>,
12011}
12012
12013/// ReadParquet
12014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12015#[cfg_attr(feature = "bindings", derive(TS))]
12016pub struct ReadParquet {
12017    #[serde(default)]
12018    pub expressions: Vec<Expression>,
12019}
12020
12021/// Reduce
12022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12023#[cfg_attr(feature = "bindings", derive(TS))]
12024pub struct Reduce {
12025    pub this: Box<Expression>,
12026    #[serde(default)]
12027    pub initial: Option<Box<Expression>>,
12028    #[serde(default)]
12029    pub merge: Option<Box<Expression>>,
12030    #[serde(default)]
12031    pub finish: Option<Box<Expression>>,
12032}
12033
12034/// RegexpExtractAll
12035#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12036#[cfg_attr(feature = "bindings", derive(TS))]
12037pub struct RegexpExtractAll {
12038    pub this: Box<Expression>,
12039    pub expression: Box<Expression>,
12040    #[serde(default)]
12041    pub group: Option<Box<Expression>>,
12042    #[serde(default)]
12043    pub parameters: Option<Box<Expression>>,
12044    #[serde(default)]
12045    pub position: Option<Box<Expression>>,
12046    #[serde(default)]
12047    pub occurrence: Option<Box<Expression>>,
12048}
12049
12050/// RegexpILike
12051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12052#[cfg_attr(feature = "bindings", derive(TS))]
12053pub struct RegexpILike {
12054    pub this: Box<Expression>,
12055    pub expression: Box<Expression>,
12056    #[serde(default)]
12057    pub flag: Option<Box<Expression>>,
12058}
12059
12060/// RegexpFullMatch
12061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12062#[cfg_attr(feature = "bindings", derive(TS))]
12063pub struct RegexpFullMatch {
12064    pub this: Box<Expression>,
12065    pub expression: Box<Expression>,
12066    #[serde(default)]
12067    pub options: Vec<Expression>,
12068}
12069
12070/// RegexpInstr
12071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12072#[cfg_attr(feature = "bindings", derive(TS))]
12073pub struct RegexpInstr {
12074    pub this: Box<Expression>,
12075    pub expression: Box<Expression>,
12076    #[serde(default)]
12077    pub position: Option<Box<Expression>>,
12078    #[serde(default)]
12079    pub occurrence: Option<Box<Expression>>,
12080    #[serde(default)]
12081    pub option: Option<Box<Expression>>,
12082    #[serde(default)]
12083    pub parameters: Option<Box<Expression>>,
12084    #[serde(default)]
12085    pub group: Option<Box<Expression>>,
12086}
12087
12088/// RegexpSplit
12089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12090#[cfg_attr(feature = "bindings", derive(TS))]
12091pub struct RegexpSplit {
12092    pub this: Box<Expression>,
12093    pub expression: Box<Expression>,
12094    #[serde(default)]
12095    pub limit: Option<Box<Expression>>,
12096}
12097
12098/// RegexpCount
12099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12100#[cfg_attr(feature = "bindings", derive(TS))]
12101pub struct RegexpCount {
12102    pub this: Box<Expression>,
12103    pub expression: Box<Expression>,
12104    #[serde(default)]
12105    pub position: Option<Box<Expression>>,
12106    #[serde(default)]
12107    pub parameters: Option<Box<Expression>>,
12108}
12109
12110/// RegrValx
12111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12112#[cfg_attr(feature = "bindings", derive(TS))]
12113pub struct RegrValx {
12114    pub this: Box<Expression>,
12115    pub expression: Box<Expression>,
12116}
12117
12118/// RegrValy
12119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12120#[cfg_attr(feature = "bindings", derive(TS))]
12121pub struct RegrValy {
12122    pub this: Box<Expression>,
12123    pub expression: Box<Expression>,
12124}
12125
12126/// RegrAvgy
12127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12128#[cfg_attr(feature = "bindings", derive(TS))]
12129pub struct RegrAvgy {
12130    pub this: Box<Expression>,
12131    pub expression: Box<Expression>,
12132}
12133
12134/// RegrAvgx
12135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12136#[cfg_attr(feature = "bindings", derive(TS))]
12137pub struct RegrAvgx {
12138    pub this: Box<Expression>,
12139    pub expression: Box<Expression>,
12140}
12141
12142/// RegrCount
12143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12144#[cfg_attr(feature = "bindings", derive(TS))]
12145pub struct RegrCount {
12146    pub this: Box<Expression>,
12147    pub expression: Box<Expression>,
12148}
12149
12150/// RegrIntercept
12151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12152#[cfg_attr(feature = "bindings", derive(TS))]
12153pub struct RegrIntercept {
12154    pub this: Box<Expression>,
12155    pub expression: Box<Expression>,
12156}
12157
12158/// RegrR2
12159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12160#[cfg_attr(feature = "bindings", derive(TS))]
12161pub struct RegrR2 {
12162    pub this: Box<Expression>,
12163    pub expression: Box<Expression>,
12164}
12165
12166/// RegrSxx
12167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12168#[cfg_attr(feature = "bindings", derive(TS))]
12169pub struct RegrSxx {
12170    pub this: Box<Expression>,
12171    pub expression: Box<Expression>,
12172}
12173
12174/// RegrSxy
12175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12176#[cfg_attr(feature = "bindings", derive(TS))]
12177pub struct RegrSxy {
12178    pub this: Box<Expression>,
12179    pub expression: Box<Expression>,
12180}
12181
12182/// RegrSyy
12183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12184#[cfg_attr(feature = "bindings", derive(TS))]
12185pub struct RegrSyy {
12186    pub this: Box<Expression>,
12187    pub expression: Box<Expression>,
12188}
12189
12190/// RegrSlope
12191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12192#[cfg_attr(feature = "bindings", derive(TS))]
12193pub struct RegrSlope {
12194    pub this: Box<Expression>,
12195    pub expression: Box<Expression>,
12196}
12197
12198/// SafeAdd
12199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12200#[cfg_attr(feature = "bindings", derive(TS))]
12201pub struct SafeAdd {
12202    pub this: Box<Expression>,
12203    pub expression: Box<Expression>,
12204}
12205
12206/// SafeDivide
12207#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12208#[cfg_attr(feature = "bindings", derive(TS))]
12209pub struct SafeDivide {
12210    pub this: Box<Expression>,
12211    pub expression: Box<Expression>,
12212}
12213
12214/// SafeMultiply
12215#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12216#[cfg_attr(feature = "bindings", derive(TS))]
12217pub struct SafeMultiply {
12218    pub this: Box<Expression>,
12219    pub expression: Box<Expression>,
12220}
12221
12222/// SafeSubtract
12223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12224#[cfg_attr(feature = "bindings", derive(TS))]
12225pub struct SafeSubtract {
12226    pub this: Box<Expression>,
12227    pub expression: Box<Expression>,
12228}
12229
12230/// SHA2
12231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12232#[cfg_attr(feature = "bindings", derive(TS))]
12233pub struct SHA2 {
12234    pub this: Box<Expression>,
12235    #[serde(default)]
12236    pub length: Option<i64>,
12237}
12238
12239/// SHA2Digest
12240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12241#[cfg_attr(feature = "bindings", derive(TS))]
12242pub struct SHA2Digest {
12243    pub this: Box<Expression>,
12244    #[serde(default)]
12245    pub length: Option<i64>,
12246}
12247
12248/// SortArray
12249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12250#[cfg_attr(feature = "bindings", derive(TS))]
12251pub struct SortArray {
12252    pub this: Box<Expression>,
12253    #[serde(default)]
12254    pub asc: Option<Box<Expression>>,
12255    #[serde(default)]
12256    pub nulls_first: Option<Box<Expression>>,
12257}
12258
12259/// SplitPart
12260#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12261#[cfg_attr(feature = "bindings", derive(TS))]
12262pub struct SplitPart {
12263    pub this: Box<Expression>,
12264    #[serde(default)]
12265    pub delimiter: Option<Box<Expression>>,
12266    #[serde(default)]
12267    pub part_index: Option<Box<Expression>>,
12268}
12269
12270/// SUBSTRING_INDEX(str, delim, count)
12271#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12272#[cfg_attr(feature = "bindings", derive(TS))]
12273pub struct SubstringIndex {
12274    pub this: Box<Expression>,
12275    #[serde(default)]
12276    pub delimiter: Option<Box<Expression>>,
12277    #[serde(default)]
12278    pub count: Option<Box<Expression>>,
12279}
12280
12281/// StandardHash
12282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12283#[cfg_attr(feature = "bindings", derive(TS))]
12284pub struct StandardHash {
12285    pub this: Box<Expression>,
12286    #[serde(default)]
12287    pub expression: Option<Box<Expression>>,
12288}
12289
12290/// StrPosition
12291#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12292#[cfg_attr(feature = "bindings", derive(TS))]
12293pub struct StrPosition {
12294    pub this: Box<Expression>,
12295    #[serde(default)]
12296    pub substr: Option<Box<Expression>>,
12297    #[serde(default)]
12298    pub position: Option<Box<Expression>>,
12299    #[serde(default)]
12300    pub occurrence: Option<Box<Expression>>,
12301}
12302
12303/// Search
12304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12305#[cfg_attr(feature = "bindings", derive(TS))]
12306pub struct Search {
12307    pub this: Box<Expression>,
12308    pub expression: Box<Expression>,
12309    #[serde(default)]
12310    pub json_scope: Option<Box<Expression>>,
12311    #[serde(default)]
12312    pub analyzer: Option<Box<Expression>>,
12313    #[serde(default)]
12314    pub analyzer_options: Option<Box<Expression>>,
12315    #[serde(default)]
12316    pub search_mode: Option<Box<Expression>>,
12317}
12318
12319/// SearchIp
12320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12321#[cfg_attr(feature = "bindings", derive(TS))]
12322pub struct SearchIp {
12323    pub this: Box<Expression>,
12324    pub expression: Box<Expression>,
12325}
12326
12327/// StrToDate
12328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12329#[cfg_attr(feature = "bindings", derive(TS))]
12330pub struct StrToDate {
12331    pub this: Box<Expression>,
12332    #[serde(default)]
12333    pub format: Option<String>,
12334    #[serde(default)]
12335    pub safe: Option<Box<Expression>>,
12336}
12337
12338/// StrToTime
12339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12340#[cfg_attr(feature = "bindings", derive(TS))]
12341pub struct StrToTime {
12342    pub this: Box<Expression>,
12343    pub format: String,
12344    #[serde(default)]
12345    pub zone: Option<Box<Expression>>,
12346    #[serde(default)]
12347    pub safe: Option<Box<Expression>>,
12348    #[serde(default)]
12349    pub target_type: Option<Box<Expression>>,
12350}
12351
12352/// StrToUnix
12353#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12354#[cfg_attr(feature = "bindings", derive(TS))]
12355pub struct StrToUnix {
12356    #[serde(default)]
12357    pub this: Option<Box<Expression>>,
12358    #[serde(default)]
12359    pub format: Option<String>,
12360}
12361
12362/// StrToMap
12363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12364#[cfg_attr(feature = "bindings", derive(TS))]
12365pub struct StrToMap {
12366    pub this: Box<Expression>,
12367    #[serde(default)]
12368    pub pair_delim: Option<Box<Expression>>,
12369    #[serde(default)]
12370    pub key_value_delim: Option<Box<Expression>>,
12371    #[serde(default)]
12372    pub duplicate_resolution_callback: Option<Box<Expression>>,
12373}
12374
12375/// NumberToStr
12376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12377#[cfg_attr(feature = "bindings", derive(TS))]
12378pub struct NumberToStr {
12379    pub this: Box<Expression>,
12380    pub format: String,
12381    #[serde(default)]
12382    pub culture: Option<Box<Expression>>,
12383}
12384
12385/// FromBase
12386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12387#[cfg_attr(feature = "bindings", derive(TS))]
12388pub struct FromBase {
12389    pub this: Box<Expression>,
12390    pub expression: Box<Expression>,
12391}
12392
12393/// Stuff
12394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12395#[cfg_attr(feature = "bindings", derive(TS))]
12396pub struct Stuff {
12397    pub this: Box<Expression>,
12398    #[serde(default)]
12399    pub start: Option<Box<Expression>>,
12400    #[serde(default)]
12401    pub length: Option<i64>,
12402    pub expression: Box<Expression>,
12403}
12404
12405/// TimeToStr
12406#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12407#[cfg_attr(feature = "bindings", derive(TS))]
12408pub struct TimeToStr {
12409    pub this: Box<Expression>,
12410    pub format: String,
12411    #[serde(default)]
12412    pub culture: Option<Box<Expression>>,
12413    #[serde(default)]
12414    pub zone: Option<Box<Expression>>,
12415}
12416
12417/// TimeStrToTime
12418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12419#[cfg_attr(feature = "bindings", derive(TS))]
12420pub struct TimeStrToTime {
12421    pub this: Box<Expression>,
12422    #[serde(default)]
12423    pub zone: Option<Box<Expression>>,
12424}
12425
12426/// TsOrDsAdd
12427#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12428#[cfg_attr(feature = "bindings", derive(TS))]
12429pub struct TsOrDsAdd {
12430    pub this: Box<Expression>,
12431    pub expression: Box<Expression>,
12432    #[serde(default)]
12433    pub unit: Option<String>,
12434    #[serde(default)]
12435    pub return_type: Option<Box<Expression>>,
12436}
12437
12438/// TsOrDsDiff
12439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12440#[cfg_attr(feature = "bindings", derive(TS))]
12441pub struct TsOrDsDiff {
12442    pub this: Box<Expression>,
12443    pub expression: Box<Expression>,
12444    #[serde(default)]
12445    pub unit: Option<String>,
12446}
12447
12448/// TsOrDsToDate
12449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12450#[cfg_attr(feature = "bindings", derive(TS))]
12451pub struct TsOrDsToDate {
12452    pub this: Box<Expression>,
12453    #[serde(default)]
12454    pub format: Option<String>,
12455    #[serde(default)]
12456    pub safe: Option<Box<Expression>>,
12457}
12458
12459/// TsOrDsToTime
12460#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12461#[cfg_attr(feature = "bindings", derive(TS))]
12462pub struct TsOrDsToTime {
12463    pub this: Box<Expression>,
12464    #[serde(default)]
12465    pub format: Option<String>,
12466    #[serde(default)]
12467    pub safe: Option<Box<Expression>>,
12468}
12469
12470/// Unhex
12471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12472#[cfg_attr(feature = "bindings", derive(TS))]
12473pub struct Unhex {
12474    pub this: Box<Expression>,
12475    #[serde(default)]
12476    pub expression: Option<Box<Expression>>,
12477}
12478
12479/// Uniform
12480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12481#[cfg_attr(feature = "bindings", derive(TS))]
12482pub struct Uniform {
12483    pub this: Box<Expression>,
12484    pub expression: Box<Expression>,
12485    #[serde(default)]
12486    pub gen: Option<Box<Expression>>,
12487    #[serde(default)]
12488    pub seed: Option<Box<Expression>>,
12489}
12490
12491/// UnixToStr
12492#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12493#[cfg_attr(feature = "bindings", derive(TS))]
12494pub struct UnixToStr {
12495    pub this: Box<Expression>,
12496    #[serde(default)]
12497    pub format: Option<String>,
12498}
12499
12500/// UnixToTime
12501#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12502#[cfg_attr(feature = "bindings", derive(TS))]
12503pub struct UnixToTime {
12504    pub this: Box<Expression>,
12505    #[serde(default)]
12506    pub scale: Option<i64>,
12507    #[serde(default)]
12508    pub zone: Option<Box<Expression>>,
12509    #[serde(default)]
12510    pub hours: Option<Box<Expression>>,
12511    #[serde(default)]
12512    pub minutes: Option<Box<Expression>>,
12513    #[serde(default)]
12514    pub format: Option<String>,
12515    #[serde(default)]
12516    pub target_type: Option<Box<Expression>>,
12517}
12518
12519/// Uuid
12520#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12521#[cfg_attr(feature = "bindings", derive(TS))]
12522pub struct Uuid {
12523    #[serde(default)]
12524    pub this: Option<Box<Expression>>,
12525    #[serde(default)]
12526    pub name: Option<String>,
12527    #[serde(default)]
12528    pub is_string: Option<Box<Expression>>,
12529}
12530
12531/// TimestampFromParts
12532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12533#[cfg_attr(feature = "bindings", derive(TS))]
12534pub struct TimestampFromParts {
12535    #[serde(default)]
12536    pub zone: Option<Box<Expression>>,
12537    #[serde(default)]
12538    pub milli: Option<Box<Expression>>,
12539    #[serde(default)]
12540    pub this: Option<Box<Expression>>,
12541    #[serde(default)]
12542    pub expression: Option<Box<Expression>>,
12543}
12544
12545/// TimestampTzFromParts
12546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12547#[cfg_attr(feature = "bindings", derive(TS))]
12548pub struct TimestampTzFromParts {
12549    #[serde(default)]
12550    pub zone: Option<Box<Expression>>,
12551}
12552
12553/// Corr
12554#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12555#[cfg_attr(feature = "bindings", derive(TS))]
12556pub struct Corr {
12557    pub this: Box<Expression>,
12558    pub expression: Box<Expression>,
12559    #[serde(default)]
12560    pub null_on_zero_variance: Option<Box<Expression>>,
12561}
12562
12563/// WidthBucket
12564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12565#[cfg_attr(feature = "bindings", derive(TS))]
12566pub struct WidthBucket {
12567    pub this: Box<Expression>,
12568    #[serde(default)]
12569    pub min_value: Option<Box<Expression>>,
12570    #[serde(default)]
12571    pub max_value: Option<Box<Expression>>,
12572    #[serde(default)]
12573    pub num_buckets: Option<Box<Expression>>,
12574    #[serde(default)]
12575    pub threshold: Option<Box<Expression>>,
12576}
12577
12578/// CovarSamp
12579#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12580#[cfg_attr(feature = "bindings", derive(TS))]
12581pub struct CovarSamp {
12582    pub this: Box<Expression>,
12583    pub expression: Box<Expression>,
12584}
12585
12586/// CovarPop
12587#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12588#[cfg_attr(feature = "bindings", derive(TS))]
12589pub struct CovarPop {
12590    pub this: Box<Expression>,
12591    pub expression: Box<Expression>,
12592}
12593
12594/// Week
12595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12596#[cfg_attr(feature = "bindings", derive(TS))]
12597pub struct Week {
12598    pub this: Box<Expression>,
12599    #[serde(default)]
12600    pub mode: Option<Box<Expression>>,
12601}
12602
12603/// XMLElement
12604#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12605#[cfg_attr(feature = "bindings", derive(TS))]
12606pub struct XMLElement {
12607    pub this: Box<Expression>,
12608    #[serde(default)]
12609    pub expressions: Vec<Expression>,
12610    #[serde(default)]
12611    pub evalname: Option<Box<Expression>>,
12612}
12613
12614/// XMLGet
12615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12616#[cfg_attr(feature = "bindings", derive(TS))]
12617pub struct XMLGet {
12618    pub this: Box<Expression>,
12619    pub expression: Box<Expression>,
12620    #[serde(default)]
12621    pub instance: Option<Box<Expression>>,
12622}
12623
12624/// XMLTable
12625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12626#[cfg_attr(feature = "bindings", derive(TS))]
12627pub struct XMLTable {
12628    pub this: Box<Expression>,
12629    #[serde(default)]
12630    pub namespaces: Option<Box<Expression>>,
12631    #[serde(default)]
12632    pub passing: Option<Box<Expression>>,
12633    #[serde(default)]
12634    pub columns: Vec<Expression>,
12635    #[serde(default)]
12636    pub by_ref: Option<Box<Expression>>,
12637}
12638
12639/// XMLKeyValueOption
12640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12641#[cfg_attr(feature = "bindings", derive(TS))]
12642pub struct XMLKeyValueOption {
12643    pub this: Box<Expression>,
12644    #[serde(default)]
12645    pub expression: Option<Box<Expression>>,
12646}
12647
12648/// Zipf
12649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12650#[cfg_attr(feature = "bindings", derive(TS))]
12651pub struct Zipf {
12652    pub this: Box<Expression>,
12653    #[serde(default)]
12654    pub elementcount: Option<Box<Expression>>,
12655    #[serde(default)]
12656    pub gen: Option<Box<Expression>>,
12657}
12658
12659/// Merge
12660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12661#[cfg_attr(feature = "bindings", derive(TS))]
12662pub struct Merge {
12663    pub this: Box<Expression>,
12664    pub using: Box<Expression>,
12665    #[serde(default)]
12666    pub on: Option<Box<Expression>>,
12667    #[serde(default)]
12668    pub using_cond: Option<Box<Expression>>,
12669    #[serde(default)]
12670    pub whens: Option<Box<Expression>>,
12671    #[serde(default)]
12672    pub with_: Option<Box<Expression>>,
12673    #[serde(default)]
12674    pub returning: Option<Box<Expression>>,
12675}
12676
12677/// When
12678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12679#[cfg_attr(feature = "bindings", derive(TS))]
12680pub struct When {
12681    #[serde(default)]
12682    pub matched: Option<Box<Expression>>,
12683    #[serde(default)]
12684    pub source: Option<Box<Expression>>,
12685    #[serde(default)]
12686    pub condition: Option<Box<Expression>>,
12687    pub then: Box<Expression>,
12688}
12689
12690/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
12691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12692#[cfg_attr(feature = "bindings", derive(TS))]
12693pub struct Whens {
12694    #[serde(default)]
12695    pub expressions: Vec<Expression>,
12696}
12697
12698/// NextValueFor
12699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12700#[cfg_attr(feature = "bindings", derive(TS))]
12701pub struct NextValueFor {
12702    pub this: Box<Expression>,
12703    #[serde(default)]
12704    pub order: Option<Box<Expression>>,
12705}
12706
12707#[cfg(test)]
12708mod tests {
12709    use super::*;
12710
12711    #[test]
12712    #[cfg(feature = "bindings")]
12713    fn export_typescript_types() {
12714        // This test exports TypeScript types to the generated directory
12715        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
12716        Expression::export_all(&ts_rs::Config::default())
12717            .expect("Failed to export Expression types");
12718    }
12719
12720    #[test]
12721    fn test_simple_select_builder() {
12722        let select = Select::new()
12723            .column(Expression::star())
12724            .from(Expression::Table(TableRef::new("users")));
12725
12726        assert_eq!(select.expressions.len(), 1);
12727        assert!(select.from.is_some());
12728    }
12729
12730    #[test]
12731    fn test_expression_alias() {
12732        let expr = Expression::column("id").alias("user_id");
12733
12734        match expr {
12735            Expression::Alias(a) => {
12736                assert_eq!(a.alias.name, "user_id");
12737            }
12738            _ => panic!("Expected Alias"),
12739        }
12740    }
12741
12742    #[test]
12743    fn test_literal_creation() {
12744        let num = Expression::number(42);
12745        let str = Expression::string("hello");
12746
12747        match num {
12748            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
12749            _ => panic!("Expected Number"),
12750        }
12751
12752        match str {
12753            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
12754            _ => panic!("Expected String"),
12755        }
12756    }
12757
12758    #[test]
12759    fn test_expression_sql() {
12760        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
12761        assert_eq!(expr.sql(), "SELECT 1 + 2");
12762    }
12763
12764    #[test]
12765    fn test_expression_sql_for() {
12766        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
12767        let sql = expr.sql_for(crate::DialectType::Generic);
12768        // Generic mode normalizes IF() to CASE WHEN
12769        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
12770    }
12771}