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    PartitionedByBucket(Box<PartitionedByBucket>),
736    PartitionByTruncate(Box<PartitionByTruncate>),
737    PartitionByRangeProperty(Box<PartitionByRangeProperty>),
738    PartitionByRangePropertyDynamic(Box<PartitionByRangePropertyDynamic>),
739    PartitionByListProperty(Box<PartitionByListProperty>),
740    PartitionList(Box<PartitionList>),
741    Partition(Box<Partition>),
742    RefreshTriggerProperty(Box<RefreshTriggerProperty>),
743    UniqueKeyProperty(Box<UniqueKeyProperty>),
744    RollupProperty(Box<RollupProperty>),
745    PartitionBoundSpec(Box<PartitionBoundSpec>),
746    PartitionedOfProperty(Box<PartitionedOfProperty>),
747    RemoteWithConnectionModelProperty(Box<RemoteWithConnectionModelProperty>),
748    ReturnsProperty(Box<ReturnsProperty>),
749    RowFormatProperty(Box<RowFormatProperty>),
750    RowFormatDelimitedProperty(Box<RowFormatDelimitedProperty>),
751    RowFormatSerdeProperty(Box<RowFormatSerdeProperty>),
752    QueryTransform(Box<QueryTransform>),
753    SampleProperty(Box<SampleProperty>),
754    SecurityProperty(Box<SecurityProperty>),
755    SchemaCommentProperty(Box<SchemaCommentProperty>),
756    SemanticView(Box<SemanticView>),
757    SerdeProperties(Box<SerdeProperties>),
758    SetProperty(Box<SetProperty>),
759    SharingProperty(Box<SharingProperty>),
760    SetConfigProperty(Box<SetConfigProperty>),
761    SettingsProperty(Box<SettingsProperty>),
762    SortKeyProperty(Box<SortKeyProperty>),
763    SqlReadWriteProperty(Box<SqlReadWriteProperty>),
764    SqlSecurityProperty(Box<SqlSecurityProperty>),
765    StabilityProperty(Box<StabilityProperty>),
766    StorageHandlerProperty(Box<StorageHandlerProperty>),
767    TemporaryProperty(Box<TemporaryProperty>),
768    Tags(Box<Tags>),
769    TransformModelProperty(Box<TransformModelProperty>),
770    TransientProperty(Box<TransientProperty>),
771    UsingTemplateProperty(Box<UsingTemplateProperty>),
772    ViewAttributeProperty(Box<ViewAttributeProperty>),
773    VolatileProperty(Box<VolatileProperty>),
774    WithDataProperty(Box<WithDataProperty>),
775    WithJournalTableProperty(Box<WithJournalTableProperty>),
776    WithSchemaBindingProperty(Box<WithSchemaBindingProperty>),
777    WithSystemVersioningProperty(Box<WithSystemVersioningProperty>),
778    WithProcedureOptions(Box<WithProcedureOptions>),
779    EncodeProperty(Box<EncodeProperty>),
780    IncludeProperty(Box<IncludeProperty>),
781    Properties(Box<Properties>),
782    InputOutputFormat(Box<InputOutputFormat>),
783    Reference(Box<Reference>),
784    QueryOption(Box<QueryOption>),
785    WithTableHint(Box<WithTableHint>),
786    IndexTableHint(Box<IndexTableHint>),
787    HistoricalData(Box<HistoricalData>),
788    Get(Box<Get>),
789    SetOperation(Box<SetOperation>),
790    Var(Box<Var>),
791    Variadic(Box<Variadic>),
792    Version(Box<Version>),
793    Schema(Box<Schema>),
794    Lock(Box<Lock>),
795    TableSample(Box<TableSample>),
796    Tag(Box<Tag>),
797    UnpivotColumns(Box<UnpivotColumns>),
798    WindowSpec(Box<WindowSpec>),
799    SessionParameter(Box<SessionParameter>),
800    PseudoType(Box<PseudoType>),
801    ObjectIdentifier(Box<ObjectIdentifier>),
802    Transaction(Box<Transaction>),
803    Commit(Box<Commit>),
804    Rollback(Box<Rollback>),
805    AlterSession(Box<AlterSession>),
806    Analyze(Box<Analyze>),
807    AnalyzeStatistics(Box<AnalyzeStatistics>),
808    AnalyzeHistogram(Box<AnalyzeHistogram>),
809    AnalyzeSample(Box<AnalyzeSample>),
810    AnalyzeListChainedRows(Box<AnalyzeListChainedRows>),
811    AnalyzeDelete(Box<AnalyzeDelete>),
812    AnalyzeWith(Box<AnalyzeWith>),
813    AnalyzeValidate(Box<AnalyzeValidate>),
814    AddPartition(Box<AddPartition>),
815    AttachOption(Box<AttachOption>),
816    DropPartition(Box<DropPartition>),
817    ReplacePartition(Box<ReplacePartition>),
818    DPipe(Box<DPipe>),
819    Operator(Box<Operator>),
820    PivotAny(Box<PivotAny>),
821    Aliases(Box<Aliases>),
822    AtIndex(Box<AtIndex>),
823    FromTimeZone(Box<FromTimeZone>),
824    FormatPhrase(Box<FormatPhrase>),
825    ForIn(Box<ForIn>),
826    TimeUnit(Box<TimeUnit>),
827    IntervalOp(Box<IntervalOp>),
828    IntervalSpan(Box<IntervalSpan>),
829    HavingMax(Box<HavingMax>),
830    CosineDistance(Box<CosineDistance>),
831    DotProduct(Box<DotProduct>),
832    EuclideanDistance(Box<EuclideanDistance>),
833    ManhattanDistance(Box<ManhattanDistance>),
834    JarowinklerSimilarity(Box<JarowinklerSimilarity>),
835    Booland(Box<Booland>),
836    Boolor(Box<Boolor>),
837    ParameterizedAgg(Box<ParameterizedAgg>),
838    ArgMax(Box<ArgMax>),
839    ArgMin(Box<ArgMin>),
840    ApproxTopK(Box<ApproxTopK>),
841    ApproxTopKAccumulate(Box<ApproxTopKAccumulate>),
842    ApproxTopKCombine(Box<ApproxTopKCombine>),
843    ApproxTopKEstimate(Box<ApproxTopKEstimate>),
844    ApproxTopSum(Box<ApproxTopSum>),
845    ApproxQuantiles(Box<ApproxQuantiles>),
846    Minhash(Box<Minhash>),
847    FarmFingerprint(Box<FarmFingerprint>),
848    Float64(Box<Float64>),
849    Transform(Box<Transform>),
850    Translate(Box<Translate>),
851    Grouping(Box<Grouping>),
852    GroupingId(Box<GroupingId>),
853    Anonymous(Box<Anonymous>),
854    AnonymousAggFunc(Box<AnonymousAggFunc>),
855    CombinedAggFunc(Box<CombinedAggFunc>),
856    CombinedParameterizedAgg(Box<CombinedParameterizedAgg>),
857    HashAgg(Box<HashAgg>),
858    Hll(Box<Hll>),
859    Apply(Box<Apply>),
860    ToBoolean(Box<ToBoolean>),
861    List(Box<List>),
862    ToMap(Box<ToMap>),
863    Pad(Box<Pad>),
864    ToChar(Box<ToChar>),
865    ToNumber(Box<ToNumber>),
866    ToDouble(Box<ToDouble>),
867    Int64(Box<UnaryFunc>),
868    StringFunc(Box<StringFunc>),
869    ToDecfloat(Box<ToDecfloat>),
870    TryToDecfloat(Box<TryToDecfloat>),
871    ToFile(Box<ToFile>),
872    Columns(Box<Columns>),
873    ConvertToCharset(Box<ConvertToCharset>),
874    ConvertTimezone(Box<ConvertTimezone>),
875    GenerateSeries(Box<GenerateSeries>),
876    AIAgg(Box<AIAgg>),
877    AIClassify(Box<AIClassify>),
878    ArrayAll(Box<ArrayAll>),
879    ArrayAny(Box<ArrayAny>),
880    ArrayConstructCompact(Box<ArrayConstructCompact>),
881    StPoint(Box<StPoint>),
882    StDistance(Box<StDistance>),
883    StringToArray(Box<StringToArray>),
884    ArraySum(Box<ArraySum>),
885    ObjectAgg(Box<ObjectAgg>),
886    CastToStrType(Box<CastToStrType>),
887    CheckJson(Box<CheckJson>),
888    CheckXml(Box<CheckXml>),
889    TranslateCharacters(Box<TranslateCharacters>),
890    CurrentSchemas(Box<CurrentSchemas>),
891    CurrentDatetime(Box<CurrentDatetime>),
892    Localtime(Box<Localtime>),
893    Localtimestamp(Box<Localtimestamp>),
894    Systimestamp(Box<Systimestamp>),
895    CurrentSchema(Box<CurrentSchema>),
896    CurrentUser(Box<CurrentUser>),
897    UtcTime(Box<UtcTime>),
898    UtcTimestamp(Box<UtcTimestamp>),
899    Timestamp(Box<TimestampFunc>),
900    DateBin(Box<DateBin>),
901    Datetime(Box<Datetime>),
902    DatetimeAdd(Box<DatetimeAdd>),
903    DatetimeSub(Box<DatetimeSub>),
904    DatetimeDiff(Box<DatetimeDiff>),
905    DatetimeTrunc(Box<DatetimeTrunc>),
906    Dayname(Box<Dayname>),
907    MakeInterval(Box<MakeInterval>),
908    PreviousDay(Box<PreviousDay>),
909    Elt(Box<Elt>),
910    TimestampAdd(Box<TimestampAdd>),
911    TimestampSub(Box<TimestampSub>),
912    TimestampDiff(Box<TimestampDiff>),
913    TimeSlice(Box<TimeSlice>),
914    TimeAdd(Box<TimeAdd>),
915    TimeSub(Box<TimeSub>),
916    TimeDiff(Box<TimeDiff>),
917    TimeTrunc(Box<TimeTrunc>),
918    DateFromParts(Box<DateFromParts>),
919    TimeFromParts(Box<TimeFromParts>),
920    DecodeCase(Box<DecodeCase>),
921    Decrypt(Box<Decrypt>),
922    DecryptRaw(Box<DecryptRaw>),
923    Encode(Box<Encode>),
924    Encrypt(Box<Encrypt>),
925    EncryptRaw(Box<EncryptRaw>),
926    EqualNull(Box<EqualNull>),
927    ToBinary(Box<ToBinary>),
928    Base64DecodeBinary(Box<Base64DecodeBinary>),
929    Base64DecodeString(Box<Base64DecodeString>),
930    Base64Encode(Box<Base64Encode>),
931    TryBase64DecodeBinary(Box<TryBase64DecodeBinary>),
932    TryBase64DecodeString(Box<TryBase64DecodeString>),
933    GapFill(Box<GapFill>),
934    GenerateDateArray(Box<GenerateDateArray>),
935    GenerateTimestampArray(Box<GenerateTimestampArray>),
936    GetExtract(Box<GetExtract>),
937    Getbit(Box<Getbit>),
938    OverflowTruncateBehavior(Box<OverflowTruncateBehavior>),
939    HexEncode(Box<HexEncode>),
940    Compress(Box<Compress>),
941    DecompressBinary(Box<DecompressBinary>),
942    DecompressString(Box<DecompressString>),
943    Xor(Box<Xor>),
944    Nullif(Box<Nullif>),
945    JSON(Box<JSON>),
946    JSONPath(Box<JSONPath>),
947    JSONPathFilter(Box<JSONPathFilter>),
948    JSONPathKey(Box<JSONPathKey>),
949    JSONPathRecursive(Box<JSONPathRecursive>),
950    JSONPathScript(Box<JSONPathScript>),
951    JSONPathSlice(Box<JSONPathSlice>),
952    JSONPathSelector(Box<JSONPathSelector>),
953    JSONPathSubscript(Box<JSONPathSubscript>),
954    JSONPathUnion(Box<JSONPathUnion>),
955    Format(Box<Format>),
956    JSONKeys(Box<JSONKeys>),
957    JSONKeyValue(Box<JSONKeyValue>),
958    JSONKeysAtDepth(Box<JSONKeysAtDepth>),
959    JSONObject(Box<JSONObject>),
960    JSONObjectAgg(Box<JSONObjectAgg>),
961    JSONBObjectAgg(Box<JSONBObjectAgg>),
962    JSONArray(Box<JSONArray>),
963    JSONArrayAgg(Box<JSONArrayAgg>),
964    JSONExists(Box<JSONExists>),
965    JSONColumnDef(Box<JSONColumnDef>),
966    JSONSchema(Box<JSONSchema>),
967    JSONSet(Box<JSONSet>),
968    JSONStripNulls(Box<JSONStripNulls>),
969    JSONValue(Box<JSONValue>),
970    JSONValueArray(Box<JSONValueArray>),
971    JSONRemove(Box<JSONRemove>),
972    JSONTable(Box<JSONTable>),
973    JSONType(Box<JSONType>),
974    ObjectInsert(Box<ObjectInsert>),
975    OpenJSONColumnDef(Box<OpenJSONColumnDef>),
976    OpenJSON(Box<OpenJSON>),
977    JSONBExists(Box<JSONBExists>),
978    JSONBContains(Box<BinaryFunc>),
979    JSONBExtract(Box<BinaryFunc>),
980    JSONCast(Box<JSONCast>),
981    JSONExtract(Box<JSONExtract>),
982    JSONExtractQuote(Box<JSONExtractQuote>),
983    JSONExtractArray(Box<JSONExtractArray>),
984    JSONExtractScalar(Box<JSONExtractScalar>),
985    JSONBExtractScalar(Box<JSONBExtractScalar>),
986    JSONFormat(Box<JSONFormat>),
987    JSONBool(Box<UnaryFunc>),
988    JSONPathRoot(JSONPathRoot),
989    JSONArrayAppend(Box<JSONArrayAppend>),
990    JSONArrayContains(Box<JSONArrayContains>),
991    JSONArrayInsert(Box<JSONArrayInsert>),
992    ParseJSON(Box<ParseJSON>),
993    ParseUrl(Box<ParseUrl>),
994    ParseIp(Box<ParseIp>),
995    ParseTime(Box<ParseTime>),
996    ParseDatetime(Box<ParseDatetime>),
997    Map(Box<Map>),
998    MapCat(Box<MapCat>),
999    MapDelete(Box<MapDelete>),
1000    MapInsert(Box<MapInsert>),
1001    MapPick(Box<MapPick>),
1002    ScopeResolution(Box<ScopeResolution>),
1003    Slice(Box<Slice>),
1004    VarMap(Box<VarMap>),
1005    MatchAgainst(Box<MatchAgainst>),
1006    MD5Digest(Box<MD5Digest>),
1007    MD5NumberLower64(Box<UnaryFunc>),
1008    MD5NumberUpper64(Box<UnaryFunc>),
1009    Monthname(Box<Monthname>),
1010    Ntile(Box<Ntile>),
1011    Normalize(Box<Normalize>),
1012    Normal(Box<Normal>),
1013    Predict(Box<Predict>),
1014    MLTranslate(Box<MLTranslate>),
1015    FeaturesAtTime(Box<FeaturesAtTime>),
1016    GenerateEmbedding(Box<GenerateEmbedding>),
1017    MLForecast(Box<MLForecast>),
1018    ModelAttribute(Box<ModelAttribute>),
1019    VectorSearch(Box<VectorSearch>),
1020    Quantile(Box<Quantile>),
1021    ApproxQuantile(Box<ApproxQuantile>),
1022    ApproxPercentileEstimate(Box<ApproxPercentileEstimate>),
1023    Randn(Box<Randn>),
1024    Randstr(Box<Randstr>),
1025    RangeN(Box<RangeN>),
1026    RangeBucket(Box<RangeBucket>),
1027    ReadCSV(Box<ReadCSV>),
1028    ReadParquet(Box<ReadParquet>),
1029    Reduce(Box<Reduce>),
1030    RegexpExtractAll(Box<RegexpExtractAll>),
1031    RegexpILike(Box<RegexpILike>),
1032    RegexpFullMatch(Box<RegexpFullMatch>),
1033    RegexpInstr(Box<RegexpInstr>),
1034    RegexpSplit(Box<RegexpSplit>),
1035    RegexpCount(Box<RegexpCount>),
1036    RegrValx(Box<RegrValx>),
1037    RegrValy(Box<RegrValy>),
1038    RegrAvgy(Box<RegrAvgy>),
1039    RegrAvgx(Box<RegrAvgx>),
1040    RegrCount(Box<RegrCount>),
1041    RegrIntercept(Box<RegrIntercept>),
1042    RegrR2(Box<RegrR2>),
1043    RegrSxx(Box<RegrSxx>),
1044    RegrSxy(Box<RegrSxy>),
1045    RegrSyy(Box<RegrSyy>),
1046    RegrSlope(Box<RegrSlope>),
1047    SafeAdd(Box<SafeAdd>),
1048    SafeDivide(Box<SafeDivide>),
1049    SafeMultiply(Box<SafeMultiply>),
1050    SafeSubtract(Box<SafeSubtract>),
1051    SHA2(Box<SHA2>),
1052    SHA2Digest(Box<SHA2Digest>),
1053    SortArray(Box<SortArray>),
1054    SplitPart(Box<SplitPart>),
1055    SubstringIndex(Box<SubstringIndex>),
1056    StandardHash(Box<StandardHash>),
1057    StrPosition(Box<StrPosition>),
1058    Search(Box<Search>),
1059    SearchIp(Box<SearchIp>),
1060    StrToDate(Box<StrToDate>),
1061    DateStrToDate(Box<UnaryFunc>),
1062    DateToDateStr(Box<UnaryFunc>),
1063    StrToTime(Box<StrToTime>),
1064    StrToUnix(Box<StrToUnix>),
1065    StrToMap(Box<StrToMap>),
1066    NumberToStr(Box<NumberToStr>),
1067    FromBase(Box<FromBase>),
1068    Stuff(Box<Stuff>),
1069    TimeToStr(Box<TimeToStr>),
1070    TimeStrToTime(Box<TimeStrToTime>),
1071    TsOrDsAdd(Box<TsOrDsAdd>),
1072    TsOrDsDiff(Box<TsOrDsDiff>),
1073    TsOrDsToDate(Box<TsOrDsToDate>),
1074    TsOrDsToTime(Box<TsOrDsToTime>),
1075    Unhex(Box<Unhex>),
1076    Uniform(Box<Uniform>),
1077    UnixToStr(Box<UnixToStr>),
1078    UnixToTime(Box<UnixToTime>),
1079    Uuid(Box<Uuid>),
1080    TimestampFromParts(Box<TimestampFromParts>),
1081    TimestampTzFromParts(Box<TimestampTzFromParts>),
1082    Corr(Box<Corr>),
1083    WidthBucket(Box<WidthBucket>),
1084    CovarSamp(Box<CovarSamp>),
1085    CovarPop(Box<CovarPop>),
1086    Week(Box<Week>),
1087    XMLElement(Box<XMLElement>),
1088    XMLGet(Box<XMLGet>),
1089    XMLTable(Box<XMLTable>),
1090    XMLKeyValueOption(Box<XMLKeyValueOption>),
1091    Zipf(Box<Zipf>),
1092    Merge(Box<Merge>),
1093    When(Box<When>),
1094    Whens(Box<Whens>),
1095    NextValueFor(Box<NextValueFor>),
1096    /// RETURN statement (DuckDB stored procedures)
1097    ReturnStmt(Box<Expression>),
1098}
1099
1100impl Expression {
1101    /// Returns `true` if this expression is a valid top-level SQL statement.
1102    ///
1103    /// Bare expressions like identifiers, literals, and function calls are not
1104    /// valid statements. This is used by `validate()` to reject inputs like
1105    /// `SELECT scooby dooby doo` which the parser splits into `SELECT scooby AS dooby`
1106    /// plus the bare identifier `doo`.
1107    pub fn is_statement(&self) -> bool {
1108        match self {
1109            // Queries
1110            Expression::Select(_)
1111            | Expression::Union(_)
1112            | Expression::Intersect(_)
1113            | Expression::Except(_)
1114            | Expression::Subquery(_)
1115            | Expression::Values(_)
1116            | Expression::PipeOperator(_)
1117
1118            // DML
1119            | Expression::Insert(_)
1120            | Expression::Update(_)
1121            | Expression::Delete(_)
1122            | Expression::Copy(_)
1123            | Expression::Put(_)
1124            | Expression::Merge(_)
1125
1126            // DDL
1127            | Expression::CreateTable(_)
1128            | Expression::DropTable(_)
1129            | Expression::AlterTable(_)
1130            | Expression::CreateIndex(_)
1131            | Expression::DropIndex(_)
1132            | Expression::CreateView(_)
1133            | Expression::DropView(_)
1134            | Expression::AlterView(_)
1135            | Expression::AlterIndex(_)
1136            | Expression::Truncate(_)
1137            | Expression::TruncateTable(_)
1138            | Expression::CreateSchema(_)
1139            | Expression::DropSchema(_)
1140            | Expression::DropNamespace(_)
1141            | Expression::CreateDatabase(_)
1142            | Expression::DropDatabase(_)
1143            | Expression::CreateFunction(_)
1144            | Expression::DropFunction(_)
1145            | Expression::CreateProcedure(_)
1146            | Expression::DropProcedure(_)
1147            | Expression::CreateSequence(_)
1148            | Expression::DropSequence(_)
1149            | Expression::AlterSequence(_)
1150            | Expression::CreateTrigger(_)
1151            | Expression::DropTrigger(_)
1152            | Expression::CreateType(_)
1153            | Expression::DropType(_)
1154            | Expression::Comment(_)
1155
1156            // Session/Transaction/Control
1157            | Expression::Use(_)
1158            | Expression::Set(_)
1159            | Expression::SetStatement(_)
1160            | Expression::Transaction(_)
1161            | Expression::Commit(_)
1162            | Expression::Rollback(_)
1163            | Expression::Grant(_)
1164            | Expression::Revoke(_)
1165            | Expression::Cache(_)
1166            | Expression::Uncache(_)
1167            | Expression::LoadData(_)
1168            | Expression::Pragma(_)
1169            | Expression::Describe(_)
1170            | Expression::Show(_)
1171            | Expression::Kill(_)
1172            | Expression::Execute(_)
1173            | Expression::Declare(_)
1174            | Expression::Refresh(_)
1175            | Expression::AlterSession(_)
1176            | Expression::LockingStatement(_)
1177
1178            // Analyze
1179            | Expression::Analyze(_)
1180            | Expression::AnalyzeStatistics(_)
1181            | Expression::AnalyzeHistogram(_)
1182            | Expression::AnalyzeSample(_)
1183            | Expression::AnalyzeListChainedRows(_)
1184            | Expression::AnalyzeDelete(_)
1185
1186            // Attach/Detach/Install/Summarize
1187            | Expression::Attach(_)
1188            | Expression::Detach(_)
1189            | Expression::Install(_)
1190            | Expression::Summarize(_)
1191
1192            // Pivot at statement level
1193            | Expression::Pivot(_)
1194            | Expression::Unpivot(_)
1195
1196            // Command (raw/unparsed statements)
1197            | Expression::Command(_)
1198            | Expression::Raw(_)
1199
1200            // Return statement
1201            | Expression::ReturnStmt(_) => true,
1202
1203            // Annotated wraps another expression with comments — check inner
1204            Expression::Annotated(a) => a.this.is_statement(),
1205
1206            // Alias at top level can wrap a statement (e.g., parenthesized subquery with alias)
1207            Expression::Alias(a) => a.this.is_statement(),
1208
1209            // Everything else (identifiers, literals, operators, functions, etc.)
1210            _ => false,
1211        }
1212    }
1213
1214    /// Create a literal number expression from an integer.
1215    pub fn number(n: i64) -> Self {
1216        Expression::Literal(Literal::Number(n.to_string()))
1217    }
1218
1219    /// Create a single-quoted literal string expression.
1220    pub fn string(s: impl Into<String>) -> Self {
1221        Expression::Literal(Literal::String(s.into()))
1222    }
1223
1224    /// Create a literal number expression from a float.
1225    pub fn float(f: f64) -> Self {
1226        Expression::Literal(Literal::Number(f.to_string()))
1227    }
1228
1229    /// Create an unqualified column reference (e.g. `name`).
1230    pub fn column(name: impl Into<String>) -> Self {
1231        Expression::Column(Column {
1232            name: Identifier::new(name),
1233            table: None,
1234            join_mark: false,
1235            trailing_comments: Vec::new(),
1236            span: None,
1237        })
1238    }
1239
1240    /// Create a qualified column reference (`table.column`).
1241    pub fn qualified_column(table: impl Into<String>, column: impl Into<String>) -> Self {
1242        Expression::Column(Column {
1243            name: Identifier::new(column),
1244            table: Some(Identifier::new(table)),
1245            join_mark: false,
1246            trailing_comments: Vec::new(),
1247            span: None,
1248        })
1249    }
1250
1251    /// Create a bare identifier expression (not a column reference).
1252    pub fn identifier(name: impl Into<String>) -> Self {
1253        Expression::Identifier(Identifier::new(name))
1254    }
1255
1256    /// Create a NULL expression
1257    pub fn null() -> Self {
1258        Expression::Null(Null)
1259    }
1260
1261    /// Create a TRUE expression
1262    pub fn true_() -> Self {
1263        Expression::Boolean(BooleanLiteral { value: true })
1264    }
1265
1266    /// Create a FALSE expression
1267    pub fn false_() -> Self {
1268        Expression::Boolean(BooleanLiteral { value: false })
1269    }
1270
1271    /// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
1272    pub fn star() -> Self {
1273        Expression::Star(Star {
1274            table: None,
1275            except: None,
1276            replace: None,
1277            rename: None,
1278            trailing_comments: Vec::new(),
1279            span: None,
1280        })
1281    }
1282
1283    /// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
1284    pub fn alias(self, name: impl Into<String>) -> Self {
1285        Expression::Alias(Box::new(Alias::new(self, Identifier::new(name))))
1286    }
1287
1288    /// Check if this is a SELECT expression
1289    pub fn is_select(&self) -> bool {
1290        matches!(self, Expression::Select(_))
1291    }
1292
1293    /// Try to get as a Select
1294    pub fn as_select(&self) -> Option<&Select> {
1295        match self {
1296            Expression::Select(s) => Some(s),
1297            _ => None,
1298        }
1299    }
1300
1301    /// Try to get as a mutable Select
1302    pub fn as_select_mut(&mut self) -> Option<&mut Select> {
1303        match self {
1304            Expression::Select(s) => Some(s),
1305            _ => None,
1306        }
1307    }
1308
1309    /// Generate a SQL string for this expression using the generic (dialect-agnostic) generator.
1310    ///
1311    /// Returns an empty string if generation fails. For dialect-specific output,
1312    /// use [`sql_for()`](Self::sql_for) instead.
1313    pub fn sql(&self) -> String {
1314        crate::generator::Generator::sql(self).unwrap_or_default()
1315    }
1316
1317    /// Generate a SQL string for this expression targeting a specific dialect.
1318    ///
1319    /// Dialect-specific rules (identifier quoting, function names, type mappings,
1320    /// syntax variations) are applied automatically.  Returns an empty string if
1321    /// generation fails.
1322    pub fn sql_for(&self, dialect: crate::dialects::DialectType) -> String {
1323        crate::generate(self, dialect).unwrap_or_default()
1324    }
1325}
1326
1327impl fmt::Display for Expression {
1328    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1329        // Basic display - full SQL generation is in generator module
1330        match self {
1331            Expression::Literal(lit) => write!(f, "{}", lit),
1332            Expression::Identifier(id) => write!(f, "{}", id),
1333            Expression::Column(col) => write!(f, "{}", col),
1334            Expression::Star(_) => write!(f, "*"),
1335            Expression::Null(_) => write!(f, "NULL"),
1336            Expression::Boolean(b) => write!(f, "{}", if b.value { "TRUE" } else { "FALSE" }),
1337            Expression::Select(_) => write!(f, "SELECT ..."),
1338            _ => write!(f, "{:?}", self),
1339        }
1340    }
1341}
1342
1343/// Represent a SQL literal value.
1344///
1345/// Numeric values are stored as their original text representation (not parsed
1346/// to `i64`/`f64`) so that precision, trailing zeros, and hex notation are
1347/// preserved across round-trips.
1348///
1349/// Dialect-specific literal forms (triple-quoted strings, dollar-quoted
1350/// strings, raw strings, etc.) each have a dedicated variant so that the
1351/// generator can emit them with the correct syntax.
1352#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1353#[cfg_attr(feature = "bindings", derive(TS))]
1354#[serde(tag = "literal_type", content = "value", rename_all = "snake_case")]
1355pub enum Literal {
1356    /// Single-quoted string literal: `'hello'`
1357    String(String),
1358    /// Numeric literal, stored as the original text: `42`, `3.14`, `1e10`
1359    Number(String),
1360    /// Hex string literal: `X'FF'`
1361    HexString(String),
1362    /// Hex number: 0xA, 0xFF (BigQuery, SQLite style) - represents an integer in hex notation
1363    HexNumber(String),
1364    BitString(String),
1365    /// Byte string: b"..." (BigQuery style)
1366    ByteString(String),
1367    /// National string: N'abc'
1368    NationalString(String),
1369    /// DATE literal: DATE '2024-01-15'
1370    Date(String),
1371    /// TIME literal: TIME '10:30:00'
1372    Time(String),
1373    /// TIMESTAMP literal: TIMESTAMP '2024-01-15 10:30:00'
1374    Timestamp(String),
1375    /// DATETIME literal: DATETIME '2024-01-15 10:30:00' (BigQuery)
1376    Datetime(String),
1377    /// Triple-quoted string: """...""" or '''...'''
1378    /// Contains (content, quote_char) where quote_char is '"' or '\''
1379    TripleQuotedString(String, char),
1380    /// Escape string: E'...' (PostgreSQL)
1381    EscapeString(String),
1382    /// Dollar-quoted string: $$...$$  (PostgreSQL)
1383    DollarString(String),
1384    /// Raw string: r"..." or r'...' (BigQuery, Spark, Databricks)
1385    /// In raw strings, backslashes are literal and not escape characters.
1386    /// When converting to a regular string, backslashes must be doubled.
1387    RawString(String),
1388}
1389
1390impl fmt::Display for Literal {
1391    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1392        match self {
1393            Literal::String(s) => write!(f, "'{}'", s),
1394            Literal::Number(n) => write!(f, "{}", n),
1395            Literal::HexString(h) => write!(f, "X'{}'", h),
1396            Literal::HexNumber(h) => write!(f, "0x{}", h),
1397            Literal::BitString(b) => write!(f, "B'{}'", b),
1398            Literal::ByteString(b) => write!(f, "b'{}'", b),
1399            Literal::NationalString(s) => write!(f, "N'{}'", s),
1400            Literal::Date(d) => write!(f, "DATE '{}'", d),
1401            Literal::Time(t) => write!(f, "TIME '{}'", t),
1402            Literal::Timestamp(ts) => write!(f, "TIMESTAMP '{}'", ts),
1403            Literal::Datetime(dt) => write!(f, "DATETIME '{}'", dt),
1404            Literal::TripleQuotedString(s, q) => {
1405                write!(f, "{0}{0}{0}{1}{0}{0}{0}", q, s)
1406            }
1407            Literal::EscapeString(s) => write!(f, "E'{}'", s),
1408            Literal::DollarString(s) => write!(f, "$${}$$", s),
1409            Literal::RawString(s) => write!(f, "r'{}'", s),
1410        }
1411    }
1412}
1413
1414/// Boolean literal
1415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1416#[cfg_attr(feature = "bindings", derive(TS))]
1417pub struct BooleanLiteral {
1418    pub value: bool,
1419}
1420
1421/// NULL literal
1422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1423#[cfg_attr(feature = "bindings", derive(TS))]
1424pub struct Null;
1425
1426/// Represent a SQL identifier (table name, column name, alias, keyword-as-name, etc.).
1427///
1428/// The `quoted` flag indicates whether the identifier was originally delimited
1429/// (double-quoted, backtick-quoted, or bracket-quoted depending on the
1430/// dialect). The generator uses this flag to decide whether to emit quoting
1431/// characters.
1432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1433#[cfg_attr(feature = "bindings", derive(TS))]
1434pub struct Identifier {
1435    /// The raw text of the identifier, without any quoting characters.
1436    pub name: String,
1437    /// Whether the identifier was quoted in the source SQL.
1438    pub quoted: bool,
1439    #[serde(default)]
1440    pub trailing_comments: Vec<String>,
1441    /// Source position span (populated during parsing, None for programmatically constructed nodes)
1442    #[serde(default, skip_serializing_if = "Option::is_none")]
1443    pub span: Option<Span>,
1444}
1445
1446impl Identifier {
1447    pub fn new(name: impl Into<String>) -> Self {
1448        Self {
1449            name: name.into(),
1450            quoted: false,
1451            trailing_comments: Vec::new(),
1452            span: None,
1453        }
1454    }
1455
1456    pub fn quoted(name: impl Into<String>) -> Self {
1457        Self {
1458            name: name.into(),
1459            quoted: true,
1460            trailing_comments: Vec::new(),
1461            span: None,
1462        }
1463    }
1464
1465    pub fn empty() -> Self {
1466        Self {
1467            name: String::new(),
1468            quoted: false,
1469            trailing_comments: Vec::new(),
1470            span: None,
1471        }
1472    }
1473
1474    pub fn is_empty(&self) -> bool {
1475        self.name.is_empty()
1476    }
1477
1478    /// Set the source span on this identifier
1479    pub fn with_span(mut self, span: Span) -> Self {
1480        self.span = Some(span);
1481        self
1482    }
1483}
1484
1485impl fmt::Display for Identifier {
1486    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1487        if self.quoted {
1488            write!(f, "\"{}\"", self.name)
1489        } else {
1490            write!(f, "{}", self.name)
1491        }
1492    }
1493}
1494
1495/// Represent a column reference, optionally qualified by a table name.
1496///
1497/// Renders as `name` when unqualified, or `table.name` when qualified.
1498/// Use [`Expression::column()`] or [`Expression::qualified_column()`] for
1499/// convenient construction.
1500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1501#[cfg_attr(feature = "bindings", derive(TS))]
1502pub struct Column {
1503    /// The column name.
1504    pub name: Identifier,
1505    /// Optional table qualifier (e.g. `t` in `t.col`).
1506    pub table: Option<Identifier>,
1507    /// Oracle-style join marker (+) for outer joins
1508    #[serde(default)]
1509    pub join_mark: bool,
1510    /// Trailing comments that appeared after this column reference
1511    #[serde(default)]
1512    pub trailing_comments: Vec<String>,
1513    /// Source position span
1514    #[serde(default, skip_serializing_if = "Option::is_none")]
1515    pub span: Option<Span>,
1516}
1517
1518impl fmt::Display for Column {
1519    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1520        if let Some(table) = &self.table {
1521            write!(f, "{}.{}", table, self.name)
1522        } else {
1523            write!(f, "{}", self.name)
1524        }
1525    }
1526}
1527
1528/// Represent a table reference with optional schema and catalog qualifiers.
1529///
1530/// Renders as `name`, `schema.name`, or `catalog.schema.name` depending on
1531/// which qualifiers are present. Supports aliases, column alias lists,
1532/// time-travel clauses (Snowflake, BigQuery), table hints (TSQL), and
1533/// several other dialect-specific extensions.
1534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1535#[cfg_attr(feature = "bindings", derive(TS))]
1536pub struct TableRef {
1537    /// The unqualified table name.
1538    pub name: Identifier,
1539    /// Optional schema qualifier (e.g. `public` in `public.users`).
1540    pub schema: Option<Identifier>,
1541    /// Optional catalog qualifier (e.g. `mydb` in `mydb.public.users`).
1542    pub catalog: Option<Identifier>,
1543    /// Optional table alias (e.g. `t` in `FROM users AS t`).
1544    pub alias: Option<Identifier>,
1545    /// Whether AS keyword was explicitly used for the alias
1546    #[serde(default)]
1547    pub alias_explicit_as: bool,
1548    /// Column aliases for table alias: AS t(c1, c2)
1549    #[serde(default)]
1550    pub column_aliases: Vec<Identifier>,
1551    /// Trailing comments that appeared after this table reference
1552    #[serde(default)]
1553    pub trailing_comments: Vec<String>,
1554    /// Snowflake time travel: BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
1555    #[serde(default)]
1556    pub when: Option<Box<HistoricalData>>,
1557    /// PostgreSQL ONLY modifier: prevents scanning child tables in inheritance hierarchy
1558    #[serde(default)]
1559    pub only: bool,
1560    /// ClickHouse FINAL modifier: forces final aggregation for MergeTree tables
1561    #[serde(default)]
1562    pub final_: bool,
1563    /// TABLESAMPLE clause attached to this table reference (DuckDB, BigQuery)
1564    #[serde(default, skip_serializing_if = "Option::is_none")]
1565    pub table_sample: Option<Box<Sample>>,
1566    /// TSQL table hints: WITH (TABLOCK, INDEX(myindex), ...)
1567    #[serde(default)]
1568    pub hints: Vec<Expression>,
1569    /// TSQL: FOR SYSTEM_TIME temporal clause
1570    /// Contains the full clause text, e.g., "FOR SYSTEM_TIME BETWEEN c AND d"
1571    #[serde(default, skip_serializing_if = "Option::is_none")]
1572    pub system_time: Option<String>,
1573    /// MySQL: PARTITION(p0, p1, ...) hint for reading from specific partitions
1574    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1575    pub partitions: Vec<Identifier>,
1576    /// Snowflake IDENTIFIER() function: dynamic table name from string/variable
1577    /// When set, this is used instead of the name field
1578    #[serde(default, skip_serializing_if = "Option::is_none")]
1579    pub identifier_func: Option<Box<Expression>>,
1580    /// Snowflake CHANGES clause: CHANGES (INFORMATION => ...) AT (...) END (...)
1581    #[serde(default, skip_serializing_if = "Option::is_none")]
1582    pub changes: Option<Box<Changes>>,
1583    /// Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
1584    #[serde(default, skip_serializing_if = "Option::is_none")]
1585    pub version: Option<Box<Version>>,
1586    /// Source position span
1587    #[serde(default, skip_serializing_if = "Option::is_none")]
1588    pub span: Option<Span>,
1589}
1590
1591impl TableRef {
1592    pub fn new(name: impl Into<String>) -> Self {
1593        Self {
1594            name: Identifier::new(name),
1595            schema: None,
1596            catalog: None,
1597            alias: None,
1598            alias_explicit_as: false,
1599            column_aliases: Vec::new(),
1600            trailing_comments: Vec::new(),
1601            when: None,
1602            only: false,
1603            final_: false,
1604            table_sample: None,
1605            hints: Vec::new(),
1606            system_time: None,
1607            partitions: Vec::new(),
1608            identifier_func: None,
1609            changes: None,
1610            version: None,
1611            span: None,
1612        }
1613    }
1614
1615    /// Create with a schema qualifier.
1616    pub fn new_with_schema(name: impl Into<String>, schema: impl Into<String>) -> Self {
1617        let mut t = Self::new(name);
1618        t.schema = Some(Identifier::new(schema));
1619        t
1620    }
1621
1622    /// Create with catalog and schema qualifiers.
1623    pub fn new_with_catalog(
1624        name: impl Into<String>,
1625        schema: impl Into<String>,
1626        catalog: impl Into<String>,
1627    ) -> Self {
1628        let mut t = Self::new(name);
1629        t.schema = Some(Identifier::new(schema));
1630        t.catalog = Some(Identifier::new(catalog));
1631        t
1632    }
1633
1634    /// Create from an Identifier, preserving the quoted flag
1635    pub fn from_identifier(name: Identifier) -> Self {
1636        Self {
1637            name,
1638            schema: None,
1639            catalog: None,
1640            alias: None,
1641            alias_explicit_as: false,
1642            column_aliases: Vec::new(),
1643            trailing_comments: Vec::new(),
1644            when: None,
1645            only: false,
1646            final_: false,
1647            table_sample: None,
1648            hints: Vec::new(),
1649            system_time: None,
1650            partitions: Vec::new(),
1651            identifier_func: None,
1652            changes: None,
1653            version: None,
1654            span: None,
1655        }
1656    }
1657
1658    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
1659        self.alias = Some(Identifier::new(alias));
1660        self
1661    }
1662
1663    pub fn with_schema(mut self, schema: impl Into<String>) -> Self {
1664        self.schema = Some(Identifier::new(schema));
1665        self
1666    }
1667}
1668
1669/// Represent a wildcard star expression (`*`, `table.*`).
1670///
1671/// Supports the EXCEPT/EXCLUDE, REPLACE, and RENAME modifiers found in
1672/// DuckDB, BigQuery, and Snowflake (e.g. `SELECT * EXCEPT (id) FROM t`).
1673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1674#[cfg_attr(feature = "bindings", derive(TS))]
1675pub struct Star {
1676    /// Optional table qualifier (e.g. `t` in `t.*`).
1677    pub table: Option<Identifier>,
1678    /// EXCLUDE / EXCEPT columns (DuckDB, BigQuery, Snowflake)
1679    pub except: Option<Vec<Identifier>>,
1680    /// REPLACE expressions (BigQuery, Snowflake)
1681    pub replace: Option<Vec<Alias>>,
1682    /// RENAME columns (Snowflake)
1683    pub rename: Option<Vec<(Identifier, Identifier)>>,
1684    /// Trailing comments that appeared after the star
1685    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1686    pub trailing_comments: Vec<String>,
1687    /// Source position span
1688    #[serde(default, skip_serializing_if = "Option::is_none")]
1689    pub span: Option<Span>,
1690}
1691
1692/// Represent a complete SELECT statement.
1693///
1694/// This is the most feature-rich AST node, covering the full surface area of
1695/// SELECT syntax across 30+ SQL dialects. Fields that are `Option` or empty
1696/// `Vec` are omitted from the generated SQL when absent.
1697///
1698/// # Key Fields
1699///
1700/// - `expressions` -- the select-list (columns, `*`, computed expressions).
1701/// - `from` -- the FROM clause. `None` for `SELECT 1` style queries.
1702/// - `joins` -- zero or more JOIN clauses, each with a [`JoinKind`].
1703/// - `where_clause` -- the WHERE predicate.
1704/// - `group_by` -- GROUP BY, including ROLLUP/CUBE/GROUPING SETS.
1705/// - `having` -- HAVING predicate.
1706/// - `order_by` -- ORDER BY with ASC/DESC and NULLS FIRST/LAST.
1707/// - `limit` / `offset` / `fetch` -- result set limiting.
1708/// - `with` -- Common Table Expressions (CTEs).
1709/// - `distinct` / `distinct_on` -- DISTINCT and PostgreSQL DISTINCT ON.
1710/// - `windows` -- named window definitions (WINDOW w AS ...).
1711///
1712/// Dialect-specific extensions are supported via fields like `prewhere`
1713/// (ClickHouse), `qualify` (Snowflake/BigQuery/DuckDB), `connect` (Oracle
1714/// CONNECT BY), `for_xml` (TSQL), and `settings` (ClickHouse).
1715#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1716#[cfg_attr(feature = "bindings", derive(TS))]
1717pub struct Select {
1718    /// The select-list: columns, expressions, aliases, and wildcards.
1719    pub expressions: Vec<Expression>,
1720    /// The FROM clause, containing one or more table sources.
1721    pub from: Option<From>,
1722    /// JOIN clauses applied after the FROM source.
1723    pub joins: Vec<Join>,
1724    pub lateral_views: Vec<LateralView>,
1725    /// ClickHouse PREWHERE clause
1726    #[serde(default, skip_serializing_if = "Option::is_none")]
1727    pub prewhere: Option<Expression>,
1728    pub where_clause: Option<Where>,
1729    pub group_by: Option<GroupBy>,
1730    pub having: Option<Having>,
1731    pub qualify: Option<Qualify>,
1732    pub order_by: Option<OrderBy>,
1733    pub distribute_by: Option<DistributeBy>,
1734    pub cluster_by: Option<ClusterBy>,
1735    pub sort_by: Option<SortBy>,
1736    pub limit: Option<Limit>,
1737    pub offset: Option<Offset>,
1738    /// ClickHouse LIMIT BY clause expressions
1739    #[serde(default, skip_serializing_if = "Option::is_none")]
1740    pub limit_by: Option<Vec<Expression>>,
1741    pub fetch: Option<Fetch>,
1742    pub distinct: bool,
1743    pub distinct_on: Option<Vec<Expression>>,
1744    pub top: Option<Top>,
1745    pub with: Option<With>,
1746    pub sample: Option<Sample>,
1747    /// ClickHouse SETTINGS clause (e.g., SETTINGS max_threads = 4)
1748    #[serde(default, skip_serializing_if = "Option::is_none")]
1749    pub settings: Option<Vec<Expression>>,
1750    /// ClickHouse FORMAT clause (e.g., FORMAT PrettyCompact)
1751    #[serde(default, skip_serializing_if = "Option::is_none")]
1752    pub format: Option<Expression>,
1753    pub windows: Option<Vec<NamedWindow>>,
1754    pub hint: Option<Hint>,
1755    /// Oracle CONNECT BY clause for hierarchical queries
1756    pub connect: Option<Connect>,
1757    /// SELECT ... INTO table_name for creating tables
1758    pub into: Option<SelectInto>,
1759    /// FOR UPDATE/SHARE locking clauses
1760    #[serde(default)]
1761    pub locks: Vec<Lock>,
1762    /// T-SQL FOR XML clause options (PATH, RAW, AUTO, EXPLICIT, BINARY BASE64, ELEMENTS XSINIL, etc.)
1763    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1764    pub for_xml: Vec<Expression>,
1765    /// Leading comments before the statement
1766    #[serde(default)]
1767    pub leading_comments: Vec<String>,
1768    /// Comments that appear after SELECT keyword (before expressions)
1769    /// Example: `SELECT <comment> col` -> `post_select_comments: ["<comment>"]`
1770    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1771    pub post_select_comments: Vec<String>,
1772    /// BigQuery SELECT AS STRUCT / SELECT AS VALUE kind
1773    #[serde(default, skip_serializing_if = "Option::is_none")]
1774    pub kind: Option<String>,
1775    /// MySQL operation modifiers (HIGH_PRIORITY, STRAIGHT_JOIN, SQL_CALC_FOUND_ROWS, etc.)
1776    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1777    pub operation_modifiers: Vec<String>,
1778    /// Whether QUALIFY appears after WINDOW (DuckDB) vs before (Snowflake/BigQuery default)
1779    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1780    pub qualify_after_window: bool,
1781    /// TSQL OPTION clause (e.g., OPTION(LABEL = 'foo'))
1782    #[serde(default, skip_serializing_if = "Option::is_none")]
1783    pub option: Option<String>,
1784}
1785
1786impl Select {
1787    pub fn new() -> Self {
1788        Self {
1789            expressions: Vec::new(),
1790            from: None,
1791            joins: Vec::new(),
1792            lateral_views: Vec::new(),
1793            prewhere: None,
1794            where_clause: None,
1795            group_by: None,
1796            having: None,
1797            qualify: None,
1798            order_by: None,
1799            distribute_by: None,
1800            cluster_by: None,
1801            sort_by: None,
1802            limit: None,
1803            offset: None,
1804            limit_by: None,
1805            fetch: None,
1806            distinct: false,
1807            distinct_on: None,
1808            top: None,
1809            with: None,
1810            sample: None,
1811            settings: None,
1812            format: None,
1813            windows: None,
1814            hint: None,
1815            connect: None,
1816            into: None,
1817            locks: Vec::new(),
1818            for_xml: Vec::new(),
1819            leading_comments: Vec::new(),
1820            post_select_comments: Vec::new(),
1821            kind: None,
1822            operation_modifiers: Vec::new(),
1823            qualify_after_window: false,
1824            option: None,
1825        }
1826    }
1827
1828    /// Add a column to select
1829    pub fn column(mut self, expr: Expression) -> Self {
1830        self.expressions.push(expr);
1831        self
1832    }
1833
1834    /// Set the FROM clause
1835    pub fn from(mut self, table: Expression) -> Self {
1836        self.from = Some(From {
1837            expressions: vec![table],
1838        });
1839        self
1840    }
1841
1842    /// Add a WHERE clause
1843    pub fn where_(mut self, condition: Expression) -> Self {
1844        self.where_clause = Some(Where { this: condition });
1845        self
1846    }
1847
1848    /// Set DISTINCT
1849    pub fn distinct(mut self) -> Self {
1850        self.distinct = true;
1851        self
1852    }
1853
1854    /// Add a JOIN
1855    pub fn join(mut self, join: Join) -> Self {
1856        self.joins.push(join);
1857        self
1858    }
1859
1860    /// Set ORDER BY
1861    pub fn order_by(mut self, expressions: Vec<Ordered>) -> Self {
1862        self.order_by = Some(OrderBy {
1863            expressions,
1864            siblings: false,
1865            comments: Vec::new(),
1866        });
1867        self
1868    }
1869
1870    /// Set LIMIT
1871    pub fn limit(mut self, n: Expression) -> Self {
1872        self.limit = Some(Limit {
1873            this: n,
1874            percent: false,
1875            comments: Vec::new(),
1876        });
1877        self
1878    }
1879
1880    /// Set OFFSET
1881    pub fn offset(mut self, n: Expression) -> Self {
1882        self.offset = Some(Offset {
1883            this: n,
1884            rows: None,
1885        });
1886        self
1887    }
1888}
1889
1890impl Default for Select {
1891    fn default() -> Self {
1892        Self::new()
1893    }
1894}
1895
1896/// Represent a UNION set operation between two query expressions.
1897///
1898/// When `all` is true, duplicate rows are preserved (UNION ALL).
1899/// ORDER BY, LIMIT, and OFFSET can be applied to the combined result.
1900/// Supports DuckDB's BY NAME modifier and BigQuery's CORRESPONDING modifier.
1901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1902#[cfg_attr(feature = "bindings", derive(TS))]
1903pub struct Union {
1904    /// The left-hand query operand.
1905    pub left: Expression,
1906    /// The right-hand query operand.
1907    pub right: Expression,
1908    /// Whether UNION ALL (true) or UNION (false, which deduplicates).
1909    pub all: bool,
1910    /// Whether DISTINCT was explicitly specified
1911    #[serde(default)]
1912    pub distinct: bool,
1913    /// Optional WITH clause
1914    pub with: Option<With>,
1915    /// ORDER BY applied to entire UNION result
1916    pub order_by: Option<OrderBy>,
1917    /// LIMIT applied to entire UNION result
1918    pub limit: Option<Box<Expression>>,
1919    /// OFFSET applied to entire UNION result
1920    pub offset: Option<Box<Expression>>,
1921    /// DISTRIBUTE BY clause (Hive/Spark)
1922    #[serde(default, skip_serializing_if = "Option::is_none")]
1923    pub distribute_by: Option<DistributeBy>,
1924    /// SORT BY clause (Hive/Spark)
1925    #[serde(default, skip_serializing_if = "Option::is_none")]
1926    pub sort_by: Option<SortBy>,
1927    /// CLUSTER BY clause (Hive/Spark)
1928    #[serde(default, skip_serializing_if = "Option::is_none")]
1929    pub cluster_by: Option<ClusterBy>,
1930    /// DuckDB BY NAME modifier
1931    #[serde(default)]
1932    pub by_name: bool,
1933    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1934    #[serde(default, skip_serializing_if = "Option::is_none")]
1935    pub side: Option<String>,
1936    /// BigQuery: Set operation kind (INNER)
1937    #[serde(default, skip_serializing_if = "Option::is_none")]
1938    pub kind: Option<String>,
1939    /// BigQuery: CORRESPONDING modifier
1940    #[serde(default)]
1941    pub corresponding: bool,
1942    /// BigQuery: STRICT modifier (before CORRESPONDING)
1943    #[serde(default)]
1944    pub strict: bool,
1945    /// BigQuery: BY (columns) after CORRESPONDING
1946    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1947    pub on_columns: Vec<Expression>,
1948}
1949
1950/// Represent an INTERSECT set operation between two query expressions.
1951///
1952/// Returns only rows that appear in both operands. When `all` is true,
1953/// duplicates are preserved according to their multiplicity.
1954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1955#[cfg_attr(feature = "bindings", derive(TS))]
1956pub struct Intersect {
1957    /// The left-hand query operand.
1958    pub left: Expression,
1959    /// The right-hand query operand.
1960    pub right: Expression,
1961    /// Whether INTERSECT ALL (true) or INTERSECT (false, which deduplicates).
1962    pub all: bool,
1963    /// Whether DISTINCT was explicitly specified
1964    #[serde(default)]
1965    pub distinct: bool,
1966    /// Optional WITH clause
1967    pub with: Option<With>,
1968    /// ORDER BY applied to entire INTERSECT result
1969    pub order_by: Option<OrderBy>,
1970    /// LIMIT applied to entire INTERSECT result
1971    pub limit: Option<Box<Expression>>,
1972    /// OFFSET applied to entire INTERSECT result
1973    pub offset: Option<Box<Expression>>,
1974    /// DISTRIBUTE BY clause (Hive/Spark)
1975    #[serde(default, skip_serializing_if = "Option::is_none")]
1976    pub distribute_by: Option<DistributeBy>,
1977    /// SORT BY clause (Hive/Spark)
1978    #[serde(default, skip_serializing_if = "Option::is_none")]
1979    pub sort_by: Option<SortBy>,
1980    /// CLUSTER BY clause (Hive/Spark)
1981    #[serde(default, skip_serializing_if = "Option::is_none")]
1982    pub cluster_by: Option<ClusterBy>,
1983    /// DuckDB BY NAME modifier
1984    #[serde(default)]
1985    pub by_name: bool,
1986    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
1987    #[serde(default, skip_serializing_if = "Option::is_none")]
1988    pub side: Option<String>,
1989    /// BigQuery: Set operation kind (INNER)
1990    #[serde(default, skip_serializing_if = "Option::is_none")]
1991    pub kind: Option<String>,
1992    /// BigQuery: CORRESPONDING modifier
1993    #[serde(default)]
1994    pub corresponding: bool,
1995    /// BigQuery: STRICT modifier (before CORRESPONDING)
1996    #[serde(default)]
1997    pub strict: bool,
1998    /// BigQuery: BY (columns) after CORRESPONDING
1999    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2000    pub on_columns: Vec<Expression>,
2001}
2002
2003/// Represent an EXCEPT (MINUS) set operation between two query expressions.
2004///
2005/// Returns rows from the left operand that do not appear in the right operand.
2006/// When `all` is true, duplicates are subtracted according to their multiplicity.
2007#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2008#[cfg_attr(feature = "bindings", derive(TS))]
2009pub struct Except {
2010    /// The left-hand query operand.
2011    pub left: Expression,
2012    /// The right-hand query operand (rows to subtract).
2013    pub right: Expression,
2014    /// Whether EXCEPT ALL (true) or EXCEPT (false, which deduplicates).
2015    pub all: bool,
2016    /// Whether DISTINCT was explicitly specified
2017    #[serde(default)]
2018    pub distinct: bool,
2019    /// Optional WITH clause
2020    pub with: Option<With>,
2021    /// ORDER BY applied to entire EXCEPT result
2022    pub order_by: Option<OrderBy>,
2023    /// LIMIT applied to entire EXCEPT result
2024    pub limit: Option<Box<Expression>>,
2025    /// OFFSET applied to entire EXCEPT result
2026    pub offset: Option<Box<Expression>>,
2027    /// DISTRIBUTE BY clause (Hive/Spark)
2028    #[serde(default, skip_serializing_if = "Option::is_none")]
2029    pub distribute_by: Option<DistributeBy>,
2030    /// SORT BY clause (Hive/Spark)
2031    #[serde(default, skip_serializing_if = "Option::is_none")]
2032    pub sort_by: Option<SortBy>,
2033    /// CLUSTER BY clause (Hive/Spark)
2034    #[serde(default, skip_serializing_if = "Option::is_none")]
2035    pub cluster_by: Option<ClusterBy>,
2036    /// DuckDB BY NAME modifier
2037    #[serde(default)]
2038    pub by_name: bool,
2039    /// BigQuery: Set operation side (LEFT, RIGHT, FULL)
2040    #[serde(default, skip_serializing_if = "Option::is_none")]
2041    pub side: Option<String>,
2042    /// BigQuery: Set operation kind (INNER)
2043    #[serde(default, skip_serializing_if = "Option::is_none")]
2044    pub kind: Option<String>,
2045    /// BigQuery: CORRESPONDING modifier
2046    #[serde(default)]
2047    pub corresponding: bool,
2048    /// BigQuery: STRICT modifier (before CORRESPONDING)
2049    #[serde(default)]
2050    pub strict: bool,
2051    /// BigQuery: BY (columns) after CORRESPONDING
2052    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2053    pub on_columns: Vec<Expression>,
2054}
2055
2056/// INTO clause for SELECT INTO statements
2057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2058#[cfg_attr(feature = "bindings", derive(TS))]
2059pub struct SelectInto {
2060    /// Target table or variable (used when single target)
2061    pub this: Expression,
2062    /// Whether TEMPORARY keyword was used
2063    #[serde(default)]
2064    pub temporary: bool,
2065    /// Whether UNLOGGED keyword was used (PostgreSQL)
2066    #[serde(default)]
2067    pub unlogged: bool,
2068    /// Whether BULK COLLECT INTO was used (Oracle PL/SQL)
2069    #[serde(default)]
2070    pub bulk_collect: bool,
2071    /// Multiple target variables (Oracle PL/SQL: BULK COLLECT INTO v1, v2)
2072    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2073    pub expressions: Vec<Expression>,
2074}
2075
2076/// Represent a parenthesized subquery expression.
2077///
2078/// A subquery wraps an inner query (typically a SELECT, UNION, etc.) in
2079/// parentheses and optionally applies an alias, column aliases, ORDER BY,
2080/// LIMIT, and OFFSET. The `modifiers_inside` flag controls whether the
2081/// modifiers are rendered inside or outside the parentheses.
2082///
2083/// Subqueries appear in many SQL contexts: FROM clauses, WHERE IN/EXISTS,
2084/// scalar subqueries in select-lists, and derived tables.
2085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2086#[cfg_attr(feature = "bindings", derive(TS))]
2087pub struct Subquery {
2088    /// The inner query expression.
2089    pub this: Expression,
2090    /// Optional alias for the derived table.
2091    pub alias: Option<Identifier>,
2092    /// Optional column aliases: AS t(c1, c2)
2093    pub column_aliases: Vec<Identifier>,
2094    /// ORDER BY clause (for parenthesized queries)
2095    pub order_by: Option<OrderBy>,
2096    /// LIMIT clause
2097    pub limit: Option<Limit>,
2098    /// OFFSET clause
2099    pub offset: Option<Offset>,
2100    /// DISTRIBUTE BY clause (Hive/Spark)
2101    #[serde(default, skip_serializing_if = "Option::is_none")]
2102    pub distribute_by: Option<DistributeBy>,
2103    /// SORT BY clause (Hive/Spark)
2104    #[serde(default, skip_serializing_if = "Option::is_none")]
2105    pub sort_by: Option<SortBy>,
2106    /// CLUSTER BY clause (Hive/Spark)
2107    #[serde(default, skip_serializing_if = "Option::is_none")]
2108    pub cluster_by: Option<ClusterBy>,
2109    /// Whether this is a LATERAL subquery (can reference earlier tables in FROM)
2110    #[serde(default)]
2111    pub lateral: bool,
2112    /// Whether modifiers (ORDER BY, LIMIT, OFFSET) should be generated inside the parentheses
2113    /// true: (SELECT 1 LIMIT 1)  - modifiers inside
2114    /// false: (SELECT 1) LIMIT 1 - modifiers outside
2115    #[serde(default)]
2116    pub modifiers_inside: bool,
2117    /// Trailing comments after the closing paren
2118    #[serde(default)]
2119    pub trailing_comments: Vec<String>,
2120}
2121
2122/// Pipe operator expression: query |> transform
2123///
2124/// Used in DataFusion and BigQuery pipe syntax:
2125///   FROM t |> WHERE x > 1 |> SELECT x, y |> ORDER BY x |> LIMIT 10
2126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2127#[cfg_attr(feature = "bindings", derive(TS))]
2128pub struct PipeOperator {
2129    /// The input query/expression (left side of |>)
2130    pub this: Expression,
2131    /// The piped operation (right side of |>)
2132    pub expression: Expression,
2133}
2134
2135/// VALUES table constructor: VALUES (1, 'a'), (2, 'b')
2136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2137#[cfg_attr(feature = "bindings", derive(TS))]
2138pub struct Values {
2139    /// The rows of values
2140    pub expressions: Vec<Tuple>,
2141    /// Optional alias for the table
2142    pub alias: Option<Identifier>,
2143    /// Optional column aliases: AS t(c1, c2)
2144    pub column_aliases: Vec<Identifier>,
2145}
2146
2147/// PIVOT operation - supports both standard and DuckDB simplified syntax
2148///
2149/// Standard syntax (in FROM clause):
2150///   table PIVOT(agg_func [AS alias], ... FOR column IN (value [AS alias], ...))
2151///   table UNPIVOT(value_col FOR name_col IN (col1, col2, ...))
2152///
2153/// DuckDB simplified syntax (statement-level):
2154///   PIVOT table ON columns [IN (...)] USING agg_func [AS alias], ... [GROUP BY ...]
2155///   UNPIVOT table ON columns INTO NAME name_col VALUE val_col
2156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2157#[cfg_attr(feature = "bindings", derive(TS))]
2158pub struct Pivot {
2159    /// Source table/expression
2160    pub this: Expression,
2161    /// For standard PIVOT: the aggregation function(s) (first is primary)
2162    /// For DuckDB simplified: unused (use `using` instead)
2163    #[serde(default)]
2164    pub expressions: Vec<Expression>,
2165    /// For standard PIVOT: the FOR...IN clause(s) as In expressions
2166    #[serde(default)]
2167    pub fields: Vec<Expression>,
2168    /// For standard: unused. For DuckDB simplified: the USING aggregation functions
2169    #[serde(default)]
2170    pub using: Vec<Expression>,
2171    /// GROUP BY clause (used in both standard inside-parens and DuckDB simplified)
2172    #[serde(default)]
2173    pub group: Option<Box<Expression>>,
2174    /// Whether this is an UNPIVOT (vs PIVOT)
2175    #[serde(default)]
2176    pub unpivot: bool,
2177    /// For DuckDB UNPIVOT: INTO NAME col VALUE col
2178    #[serde(default)]
2179    pub into: Option<Box<Expression>>,
2180    /// Optional alias
2181    #[serde(default)]
2182    pub alias: Option<Identifier>,
2183    /// Include/exclude nulls (for UNPIVOT)
2184    #[serde(default)]
2185    pub include_nulls: Option<bool>,
2186    /// Default on null value (Snowflake)
2187    #[serde(default)]
2188    pub default_on_null: Option<Box<Expression>>,
2189    /// WITH clause (CTEs)
2190    #[serde(default, skip_serializing_if = "Option::is_none")]
2191    pub with: Option<With>,
2192}
2193
2194/// UNPIVOT operation
2195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2196#[cfg_attr(feature = "bindings", derive(TS))]
2197pub struct Unpivot {
2198    pub this: Expression,
2199    pub value_column: Identifier,
2200    pub name_column: Identifier,
2201    pub columns: Vec<Expression>,
2202    pub alias: Option<Identifier>,
2203    /// Whether the value_column was parenthesized in the original SQL
2204    #[serde(default)]
2205    pub value_column_parenthesized: bool,
2206    /// INCLUDE NULLS (true), EXCLUDE NULLS (false), or not specified (None)
2207    #[serde(default)]
2208    pub include_nulls: Option<bool>,
2209    /// Additional value columns when parenthesized (e.g., (first_half_sales, second_half_sales))
2210    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2211    pub extra_value_columns: Vec<Identifier>,
2212}
2213
2214/// PIVOT alias for aliasing pivot expressions
2215/// The alias can be an identifier or an expression (for Oracle/BigQuery string concatenation aliases)
2216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2217#[cfg_attr(feature = "bindings", derive(TS))]
2218pub struct PivotAlias {
2219    pub this: Expression,
2220    pub alias: Expression,
2221}
2222
2223/// PREWHERE clause (ClickHouse) - early filtering before WHERE
2224#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2225#[cfg_attr(feature = "bindings", derive(TS))]
2226pub struct PreWhere {
2227    pub this: Expression,
2228}
2229
2230/// STREAM definition (Snowflake) - for change data capture
2231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2232#[cfg_attr(feature = "bindings", derive(TS))]
2233pub struct Stream {
2234    pub this: Expression,
2235    #[serde(skip_serializing_if = "Option::is_none")]
2236    pub on: Option<Expression>,
2237    #[serde(skip_serializing_if = "Option::is_none")]
2238    pub show_initial_rows: Option<bool>,
2239}
2240
2241/// USING DATA clause for data import statements
2242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2243#[cfg_attr(feature = "bindings", derive(TS))]
2244pub struct UsingData {
2245    pub this: Expression,
2246}
2247
2248/// XML Namespace declaration
2249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2250#[cfg_attr(feature = "bindings", derive(TS))]
2251pub struct XmlNamespace {
2252    pub this: Expression,
2253    #[serde(skip_serializing_if = "Option::is_none")]
2254    pub alias: Option<Identifier>,
2255}
2256
2257/// ROW FORMAT clause for Hive/Spark
2258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2259#[cfg_attr(feature = "bindings", derive(TS))]
2260pub struct RowFormat {
2261    pub delimited: bool,
2262    pub fields_terminated_by: Option<String>,
2263    pub collection_items_terminated_by: Option<String>,
2264    pub map_keys_terminated_by: Option<String>,
2265    pub lines_terminated_by: Option<String>,
2266    pub null_defined_as: Option<String>,
2267}
2268
2269/// Directory insert for INSERT OVERWRITE DIRECTORY (Hive/Spark)
2270#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2271#[cfg_attr(feature = "bindings", derive(TS))]
2272pub struct DirectoryInsert {
2273    pub local: bool,
2274    pub path: String,
2275    pub row_format: Option<RowFormat>,
2276    /// STORED AS clause (e.g., TEXTFILE, ORC, PARQUET)
2277    #[serde(default)]
2278    pub stored_as: Option<String>,
2279}
2280
2281/// INSERT statement
2282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2283#[cfg_attr(feature = "bindings", derive(TS))]
2284pub struct Insert {
2285    pub table: TableRef,
2286    pub columns: Vec<Identifier>,
2287    pub values: Vec<Vec<Expression>>,
2288    pub query: Option<Expression>,
2289    /// INSERT OVERWRITE for Hive/Spark
2290    pub overwrite: bool,
2291    /// PARTITION clause for Hive/Spark
2292    pub partition: Vec<(Identifier, Option<Expression>)>,
2293    /// INSERT OVERWRITE DIRECTORY for Hive/Spark
2294    #[serde(default)]
2295    pub directory: Option<DirectoryInsert>,
2296    /// RETURNING clause (PostgreSQL, SQLite)
2297    #[serde(default)]
2298    pub returning: Vec<Expression>,
2299    /// OUTPUT clause (TSQL)
2300    #[serde(default)]
2301    pub output: Option<OutputClause>,
2302    /// ON CONFLICT clause (PostgreSQL, SQLite)
2303    #[serde(default)]
2304    pub on_conflict: Option<Box<Expression>>,
2305    /// Leading comments before the statement
2306    #[serde(default)]
2307    pub leading_comments: Vec<String>,
2308    /// IF EXISTS clause (Hive)
2309    #[serde(default)]
2310    pub if_exists: bool,
2311    /// WITH clause (CTEs)
2312    #[serde(default)]
2313    pub with: Option<With>,
2314    /// INSERT IGNORE (MySQL) - ignore duplicate key errors
2315    #[serde(default)]
2316    pub ignore: bool,
2317    /// Source alias for VALUES clause (MySQL): VALUES (1, 2) AS new_data
2318    #[serde(default)]
2319    pub source_alias: Option<Identifier>,
2320    /// Table alias (PostgreSQL): INSERT INTO table AS t(...)
2321    #[serde(default)]
2322    pub alias: Option<Identifier>,
2323    /// Whether the alias uses explicit AS keyword
2324    #[serde(default)]
2325    pub alias_explicit_as: bool,
2326    /// DEFAULT VALUES (PostgreSQL): INSERT INTO t DEFAULT VALUES
2327    #[serde(default)]
2328    pub default_values: bool,
2329    /// BY NAME modifier (DuckDB): INSERT INTO x BY NAME SELECT ...
2330    #[serde(default)]
2331    pub by_name: bool,
2332    /// SQLite conflict action: INSERT OR ABORT|FAIL|IGNORE|REPLACE|ROLLBACK INTO ...
2333    #[serde(default, skip_serializing_if = "Option::is_none")]
2334    pub conflict_action: Option<String>,
2335    /// MySQL/SQLite REPLACE INTO statement (treat like INSERT)
2336    #[serde(default)]
2337    pub is_replace: bool,
2338    /// Oracle-style hint: `INSERT <hint> INTO ...` (for example Oracle APPEND hints)
2339    #[serde(default, skip_serializing_if = "Option::is_none")]
2340    pub hint: Option<Hint>,
2341    /// REPLACE WHERE clause (Databricks): INSERT INTO a REPLACE WHERE cond VALUES ...
2342    #[serde(default)]
2343    pub replace_where: Option<Box<Expression>>,
2344    /// Source table (Hive/Spark): INSERT OVERWRITE TABLE target TABLE source
2345    #[serde(default)]
2346    pub source: Option<Box<Expression>>,
2347    /// ClickHouse: INSERT INTO FUNCTION func_name(...) - the function call
2348    #[serde(default, skip_serializing_if = "Option::is_none")]
2349    pub function_target: Option<Box<Expression>>,
2350    /// ClickHouse: PARTITION BY expr
2351    #[serde(default, skip_serializing_if = "Option::is_none")]
2352    pub partition_by: Option<Box<Expression>>,
2353    /// ClickHouse: SETTINGS key = val, ...
2354    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2355    pub settings: Vec<Expression>,
2356}
2357
2358/// OUTPUT clause (TSQL) - used in INSERT, UPDATE, DELETE
2359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2360#[cfg_attr(feature = "bindings", derive(TS))]
2361pub struct OutputClause {
2362    /// Columns/expressions to output
2363    pub columns: Vec<Expression>,
2364    /// Optional INTO target table or table variable
2365    #[serde(default)]
2366    pub into_table: Option<Expression>,
2367}
2368
2369/// UPDATE statement
2370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2371#[cfg_attr(feature = "bindings", derive(TS))]
2372pub struct Update {
2373    pub table: TableRef,
2374    /// Additional tables for multi-table UPDATE (MySQL syntax)
2375    #[serde(default)]
2376    pub extra_tables: Vec<TableRef>,
2377    /// JOINs attached to the table list (MySQL multi-table syntax)
2378    #[serde(default)]
2379    pub table_joins: Vec<Join>,
2380    pub set: Vec<(Identifier, Expression)>,
2381    pub from_clause: Option<From>,
2382    /// JOINs after FROM clause (PostgreSQL, Snowflake, SQL Server syntax)
2383    #[serde(default)]
2384    pub from_joins: Vec<Join>,
2385    pub where_clause: Option<Where>,
2386    /// RETURNING clause (PostgreSQL, SQLite)
2387    #[serde(default)]
2388    pub returning: Vec<Expression>,
2389    /// OUTPUT clause (TSQL)
2390    #[serde(default)]
2391    pub output: Option<OutputClause>,
2392    /// WITH clause (CTEs)
2393    #[serde(default)]
2394    pub with: Option<With>,
2395    /// Leading comments before the statement
2396    #[serde(default)]
2397    pub leading_comments: Vec<String>,
2398    /// LIMIT clause (MySQL)
2399    #[serde(default)]
2400    pub limit: Option<Expression>,
2401    /// ORDER BY clause (MySQL)
2402    #[serde(default)]
2403    pub order_by: Option<OrderBy>,
2404    /// Whether FROM clause appears before SET (Snowflake syntax)
2405    #[serde(default)]
2406    pub from_before_set: bool,
2407}
2408
2409/// DELETE statement
2410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2411#[cfg_attr(feature = "bindings", derive(TS))]
2412pub struct Delete {
2413    pub table: TableRef,
2414    /// ClickHouse: ON CLUSTER clause for distributed DDL
2415    #[serde(default, skip_serializing_if = "Option::is_none")]
2416    pub on_cluster: Option<OnCluster>,
2417    /// Optional alias for the table
2418    pub alias: Option<Identifier>,
2419    /// Whether the alias was declared with explicit AS keyword
2420    #[serde(default)]
2421    pub alias_explicit_as: bool,
2422    /// PostgreSQL/DuckDB USING clause - additional tables to join
2423    pub using: Vec<TableRef>,
2424    pub where_clause: Option<Where>,
2425    /// OUTPUT clause (TSQL)
2426    #[serde(default)]
2427    pub output: Option<OutputClause>,
2428    /// Leading comments before the statement
2429    #[serde(default)]
2430    pub leading_comments: Vec<String>,
2431    /// WITH clause (CTEs)
2432    #[serde(default)]
2433    pub with: Option<With>,
2434    /// LIMIT clause (MySQL)
2435    #[serde(default)]
2436    pub limit: Option<Expression>,
2437    /// ORDER BY clause (MySQL)
2438    #[serde(default)]
2439    pub order_by: Option<OrderBy>,
2440    /// RETURNING clause (PostgreSQL)
2441    #[serde(default)]
2442    pub returning: Vec<Expression>,
2443    /// MySQL multi-table DELETE: DELETE t1, t2 FROM ... or DELETE FROM t1, t2 USING ...
2444    /// These are the target tables to delete from
2445    #[serde(default)]
2446    pub tables: Vec<TableRef>,
2447    /// True if tables were after FROM keyword (DELETE FROM t1, t2 USING syntax)
2448    /// False if tables were before FROM keyword (DELETE t1, t2 FROM syntax)
2449    #[serde(default)]
2450    pub tables_from_using: bool,
2451    /// JOINs in MySQL multi-table DELETE: DELETE t1 FROM t1 LEFT JOIN t2 ...
2452    #[serde(default)]
2453    pub joins: Vec<Join>,
2454    /// FORCE INDEX hint (MySQL): DELETE FROM t FORCE INDEX (idx)
2455    #[serde(default)]
2456    pub force_index: Option<String>,
2457    /// BigQuery-style DELETE without FROM keyword: DELETE table WHERE ...
2458    #[serde(default)]
2459    pub no_from: bool,
2460}
2461
2462/// COPY statement (Snowflake, PostgreSQL, DuckDB, TSQL)
2463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2464#[cfg_attr(feature = "bindings", derive(TS))]
2465pub struct CopyStmt {
2466    /// Target table or query
2467    pub this: Expression,
2468    /// True for FROM (loading into table), false for TO (exporting)
2469    pub kind: bool,
2470    /// Source/destination file(s) or stage
2471    pub files: Vec<Expression>,
2472    /// Copy parameters
2473    #[serde(default)]
2474    pub params: Vec<CopyParameter>,
2475    /// Credentials for external access
2476    #[serde(default)]
2477    pub credentials: Option<Box<Credentials>>,
2478    /// Whether the INTO keyword was used (COPY INTO vs COPY)
2479    #[serde(default)]
2480    pub is_into: bool,
2481    /// Whether parameters are wrapped in WITH (...) syntax
2482    #[serde(default)]
2483    pub with_wrapped: bool,
2484}
2485
2486/// COPY parameter (e.g., FILE_FORMAT = CSV or FORMAT PARQUET)
2487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2488#[cfg_attr(feature = "bindings", derive(TS))]
2489pub struct CopyParameter {
2490    pub name: String,
2491    pub value: Option<Expression>,
2492    pub values: Vec<Expression>,
2493    /// Whether the parameter used = sign (TSQL: KEY = VALUE vs DuckDB: KEY VALUE)
2494    #[serde(default)]
2495    pub eq: bool,
2496}
2497
2498/// Credentials for external access (S3, Azure, etc.)
2499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2500#[cfg_attr(feature = "bindings", derive(TS))]
2501pub struct Credentials {
2502    pub credentials: Vec<(String, String)>,
2503    pub encryption: Option<String>,
2504    pub storage: Option<String>,
2505}
2506
2507/// PUT statement (Snowflake)
2508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2509#[cfg_attr(feature = "bindings", derive(TS))]
2510pub struct PutStmt {
2511    /// Source file path
2512    pub source: String,
2513    /// Whether source was quoted in the original SQL
2514    #[serde(default)]
2515    pub source_quoted: bool,
2516    /// Target stage
2517    pub target: Expression,
2518    /// PUT parameters
2519    #[serde(default)]
2520    pub params: Vec<CopyParameter>,
2521}
2522
2523/// Stage reference (Snowflake) - @stage_name or @namespace.stage/path
2524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2525#[cfg_attr(feature = "bindings", derive(TS))]
2526pub struct StageReference {
2527    /// Stage name including @ prefix (e.g., "@mystage", "@namespace.mystage")
2528    pub name: String,
2529    /// Optional path within the stage (e.g., "/path/to/file.csv")
2530    #[serde(default)]
2531    pub path: Option<String>,
2532    /// Optional FILE_FORMAT parameter
2533    #[serde(default)]
2534    pub file_format: Option<Expression>,
2535    /// Optional PATTERN parameter
2536    #[serde(default)]
2537    pub pattern: Option<String>,
2538    /// Whether the stage reference was originally quoted (e.g., '@mystage')
2539    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2540    pub quoted: bool,
2541}
2542
2543/// Historical data / Time travel (Snowflake) - BEFORE (STATEMENT => ...) or AT (TIMESTAMP => ...)
2544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2545#[cfg_attr(feature = "bindings", derive(TS))]
2546pub struct HistoricalData {
2547    /// The time travel kind: "BEFORE", "AT", or "END" (as an Identifier expression)
2548    pub this: Box<Expression>,
2549    /// The time travel type: "STATEMENT", "TIMESTAMP", "OFFSET", "STREAM", or "VERSION"
2550    pub kind: String,
2551    /// The expression value (e.g., the statement ID or timestamp)
2552    pub expression: Box<Expression>,
2553}
2554
2555/// Represent an aliased expression (`expr AS name`).
2556///
2557/// Used for column aliases in select-lists, table aliases on subqueries,
2558/// and column alias lists on table-valued expressions (e.g. `AS t(c1, c2)`).
2559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2560#[cfg_attr(feature = "bindings", derive(TS))]
2561pub struct Alias {
2562    /// The expression being aliased.
2563    pub this: Expression,
2564    /// The alias name (required for simple aliases, optional when only column aliases provided)
2565    pub alias: Identifier,
2566    /// Optional column aliases for table-valued functions: AS t(col1, col2) or AS (col1, col2)
2567    #[serde(default)]
2568    pub column_aliases: Vec<Identifier>,
2569    /// Comments that appeared between the expression and AS keyword
2570    #[serde(default)]
2571    pub pre_alias_comments: Vec<String>,
2572    /// Trailing comments that appeared after the alias
2573    #[serde(default)]
2574    pub trailing_comments: Vec<String>,
2575}
2576
2577impl Alias {
2578    /// Create a simple alias
2579    pub fn new(this: Expression, alias: Identifier) -> Self {
2580        Self {
2581            this,
2582            alias,
2583            column_aliases: Vec::new(),
2584            pre_alias_comments: Vec::new(),
2585            trailing_comments: Vec::new(),
2586        }
2587    }
2588
2589    /// Create an alias with column aliases only (no table alias name)
2590    pub fn with_columns(this: Expression, column_aliases: Vec<Identifier>) -> Self {
2591        Self {
2592            this,
2593            alias: Identifier::empty(),
2594            column_aliases,
2595            pre_alias_comments: Vec::new(),
2596            trailing_comments: Vec::new(),
2597        }
2598    }
2599}
2600
2601/// Represent a type cast expression.
2602///
2603/// Covers both the standard `CAST(expr AS type)` syntax and the PostgreSQL
2604/// shorthand `expr::type`. Also used as the payload for `TryCast` and
2605/// `SafeCast` variants. Supports optional FORMAT (BigQuery) and DEFAULT ON
2606/// CONVERSION ERROR (Oracle) clauses.
2607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2608#[cfg_attr(feature = "bindings", derive(TS))]
2609pub struct Cast {
2610    /// The expression being cast.
2611    pub this: Expression,
2612    /// The target data type.
2613    pub to: DataType,
2614    #[serde(default)]
2615    pub trailing_comments: Vec<String>,
2616    /// Whether PostgreSQL `::` syntax was used (true) vs CAST() function (false)
2617    #[serde(default)]
2618    pub double_colon_syntax: bool,
2619    /// FORMAT clause for BigQuery: CAST(x AS STRING FORMAT 'format_string')
2620    #[serde(skip_serializing_if = "Option::is_none", default)]
2621    pub format: Option<Box<Expression>>,
2622    /// DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
2623    #[serde(skip_serializing_if = "Option::is_none", default)]
2624    pub default: Option<Box<Expression>>,
2625}
2626
2627///// COLLATE expression: expr COLLATE 'collation_name' or expr COLLATE collation_name
2628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2629#[cfg_attr(feature = "bindings", derive(TS))]
2630pub struct CollationExpr {
2631    pub this: Expression,
2632    pub collation: String,
2633    /// True if the collation was single-quoted in the original SQL (string literal)
2634    #[serde(default)]
2635    pub quoted: bool,
2636    /// True if the collation was double-quoted in the original SQL (identifier)
2637    #[serde(default)]
2638    pub double_quoted: bool,
2639}
2640
2641/// Represent a CASE expression (both simple and searched forms).
2642///
2643/// When `operand` is `Some`, this is a simple CASE (`CASE x WHEN 1 THEN ...`).
2644/// When `operand` is `None`, this is a searched CASE (`CASE WHEN x > 0 THEN ...`).
2645/// Each entry in `whens` is a `(condition, result)` pair.
2646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2647#[cfg_attr(feature = "bindings", derive(TS))]
2648pub struct Case {
2649    /// The operand for simple CASE, or `None` for searched CASE.
2650    pub operand: Option<Expression>,
2651    /// Pairs of (WHEN condition, THEN result).
2652    pub whens: Vec<(Expression, Expression)>,
2653    /// Optional ELSE result.
2654    pub else_: Option<Expression>,
2655    /// Comments from the CASE keyword (emitted after END)
2656    #[serde(default)]
2657    #[serde(skip_serializing_if = "Vec::is_empty")]
2658    pub comments: Vec<String>,
2659}
2660
2661/// Represent a binary operation (two operands separated by an operator).
2662///
2663/// This is the shared payload struct for all binary operator variants in the
2664/// [`Expression`] enum: arithmetic (`Add`, `Sub`, `Mul`, `Div`, `Mod`),
2665/// comparison (`Eq`, `Neq`, `Lt`, `Gt`, etc.), logical (`And`, `Or`),
2666/// bitwise, and dialect-specific operators. Comment fields enable round-trip
2667/// preservation of inline comments around operators.
2668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2669#[cfg_attr(feature = "bindings", derive(TS))]
2670pub struct BinaryOp {
2671    pub left: Expression,
2672    pub right: Expression,
2673    /// Comments after the left operand (before the operator)
2674    #[serde(default)]
2675    pub left_comments: Vec<String>,
2676    /// Comments after the operator (before the right operand)
2677    #[serde(default)]
2678    pub operator_comments: Vec<String>,
2679    /// Comments after the right operand
2680    #[serde(default)]
2681    pub trailing_comments: Vec<String>,
2682}
2683
2684impl BinaryOp {
2685    pub fn new(left: Expression, right: Expression) -> Self {
2686        Self {
2687            left,
2688            right,
2689            left_comments: Vec::new(),
2690            operator_comments: Vec::new(),
2691            trailing_comments: Vec::new(),
2692        }
2693    }
2694}
2695
2696/// LIKE/ILIKE operation with optional ESCAPE clause and quantifier (ANY/ALL)
2697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2698#[cfg_attr(feature = "bindings", derive(TS))]
2699pub struct LikeOp {
2700    pub left: Expression,
2701    pub right: Expression,
2702    /// ESCAPE character/expression
2703    #[serde(default)]
2704    pub escape: Option<Expression>,
2705    /// Quantifier: ANY, ALL, or SOME
2706    #[serde(default)]
2707    pub quantifier: Option<String>,
2708}
2709
2710impl LikeOp {
2711    pub fn new(left: Expression, right: Expression) -> Self {
2712        Self {
2713            left,
2714            right,
2715            escape: None,
2716            quantifier: None,
2717        }
2718    }
2719
2720    pub fn with_escape(left: Expression, right: Expression, escape: Expression) -> Self {
2721        Self {
2722            left,
2723            right,
2724            escape: Some(escape),
2725            quantifier: None,
2726        }
2727    }
2728}
2729
2730/// Represent a unary operation (single operand with a prefix operator).
2731///
2732/// Shared payload for `Not`, `Neg`, and `BitwiseNot` variants.
2733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2734#[cfg_attr(feature = "bindings", derive(TS))]
2735pub struct UnaryOp {
2736    /// The operand expression.
2737    pub this: Expression,
2738}
2739
2740impl UnaryOp {
2741    pub fn new(this: Expression) -> Self {
2742        Self { this }
2743    }
2744}
2745
2746/// Represent an IN predicate (`x IN (1, 2, 3)` or `x IN (SELECT ...)`).
2747///
2748/// Either `expressions` (a value list) or `query` (a subquery) is populated,
2749/// but not both. When `not` is true, the predicate is `NOT IN`.
2750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2751#[cfg_attr(feature = "bindings", derive(TS))]
2752pub struct In {
2753    /// The expression being tested.
2754    pub this: Expression,
2755    /// The value list (mutually exclusive with `query`).
2756    pub expressions: Vec<Expression>,
2757    /// A subquery (mutually exclusive with `expressions`).
2758    pub query: Option<Expression>,
2759    /// Whether this is NOT IN.
2760    pub not: bool,
2761    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2762    pub global: bool,
2763    /// BigQuery: IN UNNEST(expr)
2764    #[serde(default, skip_serializing_if = "Option::is_none")]
2765    pub unnest: Option<Box<Expression>>,
2766    /// Whether the right side is a bare field reference (no parentheses).
2767    /// Matches Python sqlglot's `field` attribute on `In` expression.
2768    /// e.g., `a IN subquery1` vs `a IN (subquery1)`
2769    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
2770    pub is_field: bool,
2771}
2772
2773/// Represent a BETWEEN predicate (`x BETWEEN low AND high`).
2774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2775#[cfg_attr(feature = "bindings", derive(TS))]
2776pub struct Between {
2777    /// The expression being tested.
2778    pub this: Expression,
2779    /// The lower bound.
2780    pub low: Expression,
2781    /// The upper bound.
2782    pub high: Expression,
2783    /// Whether this is NOT BETWEEN.
2784    pub not: bool,
2785    /// SYMMETRIC/ASYMMETRIC qualifier: None = regular, Some(true) = SYMMETRIC, Some(false) = ASYMMETRIC
2786    #[serde(default)]
2787    pub symmetric: Option<bool>,
2788}
2789
2790/// IS NULL predicate
2791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2792#[cfg_attr(feature = "bindings", derive(TS))]
2793pub struct IsNull {
2794    pub this: Expression,
2795    pub not: bool,
2796    /// Whether this was the postfix form (ISNULL/NOTNULL) vs standard (IS NULL/IS NOT NULL)
2797    #[serde(default)]
2798    pub postfix_form: bool,
2799}
2800
2801/// IS TRUE / IS FALSE predicate
2802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2803#[cfg_attr(feature = "bindings", derive(TS))]
2804pub struct IsTrueFalse {
2805    pub this: Expression,
2806    pub not: bool,
2807}
2808
2809/// IS JSON predicate (SQL standard)
2810/// Checks if a value is valid JSON
2811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2812#[cfg_attr(feature = "bindings", derive(TS))]
2813pub struct IsJson {
2814    pub this: Expression,
2815    /// JSON type: VALUE, SCALAR, OBJECT, or ARRAY (None = just IS JSON)
2816    pub json_type: Option<String>,
2817    /// Key uniqueness constraint
2818    pub unique_keys: Option<JsonUniqueKeys>,
2819    /// Whether IS NOT JSON
2820    pub negated: bool,
2821}
2822
2823/// JSON unique keys constraint variants
2824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2825#[cfg_attr(feature = "bindings", derive(TS))]
2826pub enum JsonUniqueKeys {
2827    /// WITH UNIQUE KEYS
2828    With,
2829    /// WITHOUT UNIQUE KEYS
2830    Without,
2831    /// UNIQUE KEYS (shorthand for WITH UNIQUE KEYS)
2832    Shorthand,
2833}
2834
2835/// Represent an EXISTS predicate (`EXISTS (SELECT ...)` or `NOT EXISTS (...)`).
2836#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2837#[cfg_attr(feature = "bindings", derive(TS))]
2838pub struct Exists {
2839    /// The subquery expression.
2840    pub this: Expression,
2841    /// Whether this is NOT EXISTS.
2842    pub not: bool,
2843}
2844
2845/// Represent a scalar function call (e.g. `UPPER(name)`, `COALESCE(a, b)`).
2846///
2847/// This is the generic function node. Well-known aggregates, window functions,
2848/// and built-in functions each have their own dedicated `Expression` variants
2849/// (e.g. `Count`, `Sum`, `WindowFunction`). Functions that the parser does
2850/// not recognize as built-ins are represented with this struct.
2851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2852#[cfg_attr(feature = "bindings", derive(TS))]
2853pub struct Function {
2854    /// The function name, as originally written (may be schema-qualified).
2855    pub name: String,
2856    /// Positional arguments to the function.
2857    pub args: Vec<Expression>,
2858    /// Whether DISTINCT was specified inside the call (e.g. `COUNT(DISTINCT x)`).
2859    pub distinct: bool,
2860    #[serde(default)]
2861    pub trailing_comments: Vec<String>,
2862    /// Whether this function uses bracket syntax (e.g., MAP[keys, values])
2863    #[serde(default)]
2864    pub use_bracket_syntax: bool,
2865    /// Whether this function was called without parentheses (e.g., CURRENT_TIMESTAMP vs CURRENT_TIMESTAMP())
2866    #[serde(default)]
2867    pub no_parens: bool,
2868    /// Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
2869    #[serde(default)]
2870    pub quoted: bool,
2871    /// Source position span
2872    #[serde(default, skip_serializing_if = "Option::is_none")]
2873    pub span: Option<Span>,
2874}
2875
2876impl Default for Function {
2877    fn default() -> Self {
2878        Self {
2879            name: String::new(),
2880            args: Vec::new(),
2881            distinct: false,
2882            trailing_comments: Vec::new(),
2883            use_bracket_syntax: false,
2884            no_parens: false,
2885            quoted: false,
2886            span: None,
2887        }
2888    }
2889}
2890
2891impl Function {
2892    pub fn new(name: impl Into<String>, args: Vec<Expression>) -> Self {
2893        Self {
2894            name: name.into(),
2895            args,
2896            distinct: false,
2897            trailing_comments: Vec::new(),
2898            use_bracket_syntax: false,
2899            no_parens: false,
2900            quoted: false,
2901            span: None,
2902        }
2903    }
2904}
2905
2906/// Represent a named aggregate function call with optional FILTER, ORDER BY, and LIMIT.
2907///
2908/// This struct is used for aggregate function calls that are not covered by
2909/// one of the dedicated typed variants (e.g. `Count`, `Sum`). It supports
2910/// SQL:2003 FILTER (WHERE ...) clauses, ordered-set aggregates, and
2911/// IGNORE NULLS / RESPECT NULLS modifiers.
2912#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
2913#[cfg_attr(feature = "bindings", derive(TS))]
2914pub struct AggregateFunction {
2915    /// The aggregate function name (e.g. "JSON_AGG", "XMLAGG").
2916    pub name: String,
2917    /// Positional arguments.
2918    pub args: Vec<Expression>,
2919    /// Whether DISTINCT was specified.
2920    pub distinct: bool,
2921    /// Optional FILTER (WHERE ...) clause applied to the aggregate.
2922    pub filter: Option<Expression>,
2923    /// ORDER BY inside aggregate (e.g., JSON_AGG(x ORDER BY y))
2924    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2925    pub order_by: Vec<Ordered>,
2926    /// LIMIT inside aggregate (e.g., ARRAY_CONCAT_AGG(x LIMIT 2))
2927    #[serde(default, skip_serializing_if = "Option::is_none")]
2928    pub limit: Option<Box<Expression>>,
2929    /// IGNORE NULLS / RESPECT NULLS
2930    #[serde(default, skip_serializing_if = "Option::is_none")]
2931    pub ignore_nulls: Option<bool>,
2932}
2933
2934/// Represent a window function call with its OVER clause.
2935///
2936/// The inner `this` expression is typically a window-specific expression
2937/// (e.g. `RowNumber`, `Rank`, `Lead`) or an aggregate used as a window
2938/// function.  The `over` field carries the PARTITION BY, ORDER BY, and
2939/// frame specification.
2940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2941#[cfg_attr(feature = "bindings", derive(TS))]
2942pub struct WindowFunction {
2943    /// The function expression (e.g. ROW_NUMBER(), SUM(amount)).
2944    pub this: Expression,
2945    /// The OVER clause defining the window partitioning, ordering, and frame.
2946    pub over: Over,
2947    /// Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
2948    #[serde(default, skip_serializing_if = "Option::is_none")]
2949    pub keep: Option<Keep>,
2950}
2951
2952/// Oracle KEEP clause for aggregate functions
2953/// Syntax: aggregate_function KEEP (DENSE_RANK FIRST|LAST ORDER BY column [ASC|DESC])
2954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2955#[cfg_attr(feature = "bindings", derive(TS))]
2956pub struct Keep {
2957    /// true = FIRST, false = LAST
2958    pub first: bool,
2959    /// ORDER BY clause inside KEEP
2960    pub order_by: Vec<Ordered>,
2961}
2962
2963/// WITHIN GROUP clause (for ordered-set aggregate functions)
2964#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2965#[cfg_attr(feature = "bindings", derive(TS))]
2966pub struct WithinGroup {
2967    /// The aggregate function (LISTAGG, PERCENTILE_CONT, etc.)
2968    pub this: Expression,
2969    /// The ORDER BY clause within the group
2970    pub order_by: Vec<Ordered>,
2971}
2972
2973/// Represent the FROM clause of a SELECT statement.
2974///
2975/// Contains one or more table sources (tables, subqueries, table-valued
2976/// functions, etc.). Multiple entries represent comma-separated implicit joins.
2977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2978#[cfg_attr(feature = "bindings", derive(TS))]
2979pub struct From {
2980    /// The table source expressions.
2981    pub expressions: Vec<Expression>,
2982}
2983
2984/// Represent a JOIN clause between two table sources.
2985///
2986/// The join condition can be specified via `on` (ON predicate) or `using`
2987/// (USING column list), but not both. The `kind` field determines the join
2988/// type (INNER, LEFT, CROSS, etc.).
2989#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2990#[cfg_attr(feature = "bindings", derive(TS))]
2991pub struct Join {
2992    /// The right-hand table expression being joined.
2993    pub this: Expression,
2994    /// The ON condition (mutually exclusive with `using`).
2995    pub on: Option<Expression>,
2996    /// The USING column list (mutually exclusive with `on`).
2997    pub using: Vec<Identifier>,
2998    /// The join type (INNER, LEFT, RIGHT, FULL, CROSS, etc.).
2999    pub kind: JoinKind,
3000    /// Whether INNER keyword was explicitly used (INNER JOIN vs JOIN)
3001    pub use_inner_keyword: bool,
3002    /// Whether OUTER keyword was explicitly used (LEFT OUTER JOIN vs LEFT JOIN)
3003    pub use_outer_keyword: bool,
3004    /// Whether the ON/USING condition was deferred (assigned right-to-left for chained JOINs)
3005    pub deferred_condition: bool,
3006    /// TSQL join hint: LOOP, HASH, MERGE (e.g., INNER LOOP JOIN)
3007    #[serde(default, skip_serializing_if = "Option::is_none")]
3008    pub join_hint: Option<String>,
3009    /// Snowflake ASOF JOIN match condition (MATCH_CONDITION clause)
3010    #[serde(default, skip_serializing_if = "Option::is_none")]
3011    pub match_condition: Option<Expression>,
3012    /// PIVOT/UNPIVOT operations that follow this join (Oracle/TSQL syntax)
3013    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3014    pub pivots: Vec<Expression>,
3015    /// Comments collected between join-kind keywords (for example `INNER <comment> JOIN`)
3016    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3017    pub comments: Vec<String>,
3018    /// Nesting group identifier for nested join pretty-printing.
3019    /// Joins in the same group were parsed together; group boundaries come from
3020    /// deferred condition resolution phases.
3021    #[serde(default)]
3022    pub nesting_group: usize,
3023    /// Snowflake: DIRECTED keyword in JOIN (e.g., CROSS DIRECTED JOIN)
3024    #[serde(default)]
3025    pub directed: bool,
3026}
3027
3028/// Enumerate all supported SQL join types.
3029///
3030/// Covers the standard join types (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL)
3031/// as well as dialect-specific variants: SEMI/ANTI joins, LATERAL joins,
3032/// CROSS/OUTER APPLY (TSQL), ASOF joins (DuckDB/Snowflake), ARRAY joins
3033/// (ClickHouse), STRAIGHT_JOIN (MySQL), and implicit comma-joins.
3034#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3035#[cfg_attr(feature = "bindings", derive(TS))]
3036pub enum JoinKind {
3037    Inner,
3038    Left,
3039    Right,
3040    Full,
3041    Outer, // Standalone OUTER JOIN (without LEFT/RIGHT/FULL)
3042    Cross,
3043    Natural,
3044    NaturalLeft,
3045    NaturalRight,
3046    NaturalFull,
3047    Semi,
3048    Anti,
3049    // Directional SEMI/ANTI joins
3050    LeftSemi,
3051    LeftAnti,
3052    RightSemi,
3053    RightAnti,
3054    // SQL Server specific
3055    CrossApply,
3056    OuterApply,
3057    // Time-series specific
3058    AsOf,
3059    AsOfLeft,
3060    AsOfRight,
3061    // Lateral join
3062    Lateral,
3063    LeftLateral,
3064    // MySQL specific
3065    Straight,
3066    // Implicit join (comma-separated tables: FROM a, b)
3067    Implicit,
3068    // ClickHouse ARRAY JOIN
3069    Array,
3070    LeftArray,
3071    // ClickHouse PASTE JOIN (positional join)
3072    Paste,
3073}
3074
3075impl Default for JoinKind {
3076    fn default() -> Self {
3077        JoinKind::Inner
3078    }
3079}
3080
3081/// Parenthesized table expression with joins
3082/// Represents: (tbl1 CROSS JOIN tbl2) or ((SELECT 1) CROSS JOIN (SELECT 2))
3083#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3084#[cfg_attr(feature = "bindings", derive(TS))]
3085pub struct JoinedTable {
3086    /// The left-hand side table expression
3087    pub left: Expression,
3088    /// The joins applied to the left table
3089    pub joins: Vec<Join>,
3090    /// LATERAL VIEW clauses (Hive/Spark)
3091    pub lateral_views: Vec<LateralView>,
3092    /// Optional alias for the joined table expression
3093    pub alias: Option<Identifier>,
3094}
3095
3096/// Represent a WHERE clause containing a boolean filter predicate.
3097#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3098#[cfg_attr(feature = "bindings", derive(TS))]
3099pub struct Where {
3100    /// The filter predicate expression.
3101    pub this: Expression,
3102}
3103
3104/// Represent a GROUP BY clause with optional ALL/DISTINCT and WITH TOTALS modifiers.
3105///
3106/// The `expressions` list may contain plain columns, ordinal positions,
3107/// ROLLUP/CUBE/GROUPING SETS expressions, or the special empty-set `()`.
3108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3109#[cfg_attr(feature = "bindings", derive(TS))]
3110pub struct GroupBy {
3111    /// The grouping expressions.
3112    pub expressions: Vec<Expression>,
3113    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
3114    #[serde(default)]
3115    pub all: Option<bool>,
3116    /// ClickHouse: WITH TOTALS modifier
3117    #[serde(default)]
3118    pub totals: bool,
3119    /// Leading comments that appeared before the GROUP BY keyword
3120    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3121    pub comments: Vec<String>,
3122}
3123
3124/// Represent a HAVING clause containing a predicate over aggregate results.
3125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3126#[cfg_attr(feature = "bindings", derive(TS))]
3127pub struct Having {
3128    /// The filter predicate, typically involving aggregate functions.
3129    pub this: Expression,
3130    /// Leading comments that appeared before the HAVING keyword
3131    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3132    pub comments: Vec<String>,
3133}
3134
3135/// Represent an ORDER BY clause containing one or more sort specifications.
3136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3137#[cfg_attr(feature = "bindings", derive(TS))]
3138pub struct OrderBy {
3139    /// The sort specifications, each with direction and null ordering.
3140    pub expressions: Vec<Ordered>,
3141    /// Whether this is ORDER SIBLINGS BY (Oracle hierarchical queries)
3142    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3143    pub siblings: bool,
3144    /// Leading comments that appeared before the ORDER BY keyword
3145    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3146    pub comments: Vec<String>,
3147}
3148
3149/// Represent an expression with sort direction and null ordering.
3150///
3151/// Used inside ORDER BY clauses, window frame ORDER BY, and index definitions.
3152/// When `desc` is false the sort is ascending. The `nulls_first` field
3153/// controls the NULLS FIRST / NULLS LAST modifier; `None` means unspecified
3154/// (database default).
3155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3156#[cfg_attr(feature = "bindings", derive(TS))]
3157pub struct Ordered {
3158    /// The expression to sort by.
3159    pub this: Expression,
3160    /// Whether the sort direction is descending (true) or ascending (false).
3161    pub desc: bool,
3162    /// `Some(true)` = NULLS FIRST, `Some(false)` = NULLS LAST, `None` = unspecified.
3163    pub nulls_first: Option<bool>,
3164    /// Whether ASC was explicitly written (not just implied)
3165    #[serde(default)]
3166    pub explicit_asc: bool,
3167    /// ClickHouse WITH FILL clause
3168    #[serde(default, skip_serializing_if = "Option::is_none")]
3169    pub with_fill: Option<Box<WithFill>>,
3170}
3171
3172impl Ordered {
3173    pub fn asc(expr: Expression) -> Self {
3174        Self {
3175            this: expr,
3176            desc: false,
3177            nulls_first: None,
3178            explicit_asc: false,
3179            with_fill: None,
3180        }
3181    }
3182
3183    pub fn desc(expr: Expression) -> Self {
3184        Self {
3185            this: expr,
3186            desc: true,
3187            nulls_first: None,
3188            explicit_asc: false,
3189            with_fill: None,
3190        }
3191    }
3192}
3193
3194/// DISTRIBUTE BY clause (Hive/Spark)
3195/// Controls how rows are distributed across reducers
3196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3197#[cfg_attr(feature = "bindings", derive(TS))]
3198#[cfg_attr(feature = "bindings", ts(export))]
3199pub struct DistributeBy {
3200    pub expressions: Vec<Expression>,
3201}
3202
3203/// CLUSTER BY clause (Hive/Spark)
3204/// Combines DISTRIBUTE BY and SORT BY on the same columns
3205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3206#[cfg_attr(feature = "bindings", derive(TS))]
3207#[cfg_attr(feature = "bindings", ts(export))]
3208pub struct ClusterBy {
3209    pub expressions: Vec<Ordered>,
3210}
3211
3212/// SORT BY clause (Hive/Spark)
3213/// Sorts data within each reducer (local sort, not global)
3214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3215#[cfg_attr(feature = "bindings", derive(TS))]
3216#[cfg_attr(feature = "bindings", ts(export))]
3217pub struct SortBy {
3218    pub expressions: Vec<Ordered>,
3219}
3220
3221/// LATERAL VIEW clause (Hive/Spark)
3222/// Used for unnesting arrays/maps with EXPLODE, POSEXPLODE, etc.
3223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3224#[cfg_attr(feature = "bindings", derive(TS))]
3225#[cfg_attr(feature = "bindings", ts(export))]
3226pub struct LateralView {
3227    /// The table-generating function (EXPLODE, POSEXPLODE, etc.)
3228    pub this: Expression,
3229    /// Table alias for the generated table
3230    pub table_alias: Option<Identifier>,
3231    /// Column aliases for the generated columns
3232    pub column_aliases: Vec<Identifier>,
3233    /// OUTER keyword - preserve nulls when input is empty/null
3234    pub outer: bool,
3235}
3236
3237/// Query hint
3238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3239#[cfg_attr(feature = "bindings", derive(TS))]
3240#[cfg_attr(feature = "bindings", ts(export))]
3241pub struct Hint {
3242    pub expressions: Vec<HintExpression>,
3243}
3244
3245/// Individual hint expression
3246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3247#[cfg_attr(feature = "bindings", derive(TS))]
3248#[cfg_attr(feature = "bindings", ts(export))]
3249pub enum HintExpression {
3250    /// Function-style hint: USE_HASH(table)
3251    Function { name: String, args: Vec<Expression> },
3252    /// Simple identifier hint: PARALLEL
3253    Identifier(String),
3254    /// Raw hint text (unparsed)
3255    Raw(String),
3256}
3257
3258/// Pseudocolumn type
3259#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3260#[cfg_attr(feature = "bindings", derive(TS))]
3261#[cfg_attr(feature = "bindings", ts(export))]
3262pub enum PseudocolumnType {
3263    Rownum,      // Oracle ROWNUM
3264    Rowid,       // Oracle ROWID
3265    Level,       // Oracle LEVEL (for CONNECT BY)
3266    Sysdate,     // Oracle SYSDATE
3267    ObjectId,    // Oracle OBJECT_ID
3268    ObjectValue, // Oracle OBJECT_VALUE
3269}
3270
3271impl PseudocolumnType {
3272    pub fn as_str(&self) -> &'static str {
3273        match self {
3274            PseudocolumnType::Rownum => "ROWNUM",
3275            PseudocolumnType::Rowid => "ROWID",
3276            PseudocolumnType::Level => "LEVEL",
3277            PseudocolumnType::Sysdate => "SYSDATE",
3278            PseudocolumnType::ObjectId => "OBJECT_ID",
3279            PseudocolumnType::ObjectValue => "OBJECT_VALUE",
3280        }
3281    }
3282
3283    pub fn from_str(s: &str) -> Option<Self> {
3284        match s.to_uppercase().as_str() {
3285            "ROWNUM" => Some(PseudocolumnType::Rownum),
3286            "ROWID" => Some(PseudocolumnType::Rowid),
3287            "LEVEL" => Some(PseudocolumnType::Level),
3288            "SYSDATE" => Some(PseudocolumnType::Sysdate),
3289            "OBJECT_ID" => Some(PseudocolumnType::ObjectId),
3290            "OBJECT_VALUE" => Some(PseudocolumnType::ObjectValue),
3291            _ => None,
3292        }
3293    }
3294}
3295
3296/// Pseudocolumn expression (Oracle ROWNUM, ROWID, LEVEL, etc.)
3297/// These are special identifiers that should not be quoted
3298#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3299#[cfg_attr(feature = "bindings", derive(TS))]
3300#[cfg_attr(feature = "bindings", ts(export))]
3301pub struct Pseudocolumn {
3302    pub kind: PseudocolumnType,
3303}
3304
3305impl Pseudocolumn {
3306    pub fn rownum() -> Self {
3307        Self {
3308            kind: PseudocolumnType::Rownum,
3309        }
3310    }
3311
3312    pub fn rowid() -> Self {
3313        Self {
3314            kind: PseudocolumnType::Rowid,
3315        }
3316    }
3317
3318    pub fn level() -> Self {
3319        Self {
3320            kind: PseudocolumnType::Level,
3321        }
3322    }
3323}
3324
3325/// Oracle CONNECT BY clause for hierarchical queries
3326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3327#[cfg_attr(feature = "bindings", derive(TS))]
3328#[cfg_attr(feature = "bindings", ts(export))]
3329pub struct Connect {
3330    /// START WITH condition (optional, can come before or after CONNECT BY)
3331    pub start: Option<Expression>,
3332    /// CONNECT BY condition (required, contains PRIOR references)
3333    pub connect: Expression,
3334    /// NOCYCLE keyword to prevent infinite loops
3335    pub nocycle: bool,
3336}
3337
3338/// Oracle PRIOR expression - references parent row's value in CONNECT BY
3339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3340#[cfg_attr(feature = "bindings", derive(TS))]
3341#[cfg_attr(feature = "bindings", ts(export))]
3342pub struct Prior {
3343    pub this: Expression,
3344}
3345
3346/// Oracle CONNECT_BY_ROOT function - returns root row's column value
3347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3348#[cfg_attr(feature = "bindings", derive(TS))]
3349#[cfg_attr(feature = "bindings", ts(export))]
3350pub struct ConnectByRoot {
3351    pub this: Expression,
3352}
3353
3354/// MATCH_RECOGNIZE clause for row pattern matching (Oracle/Snowflake/Presto/Trino)
3355#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3356#[cfg_attr(feature = "bindings", derive(TS))]
3357#[cfg_attr(feature = "bindings", ts(export))]
3358pub struct MatchRecognize {
3359    /// Source table/expression
3360    pub this: Option<Box<Expression>>,
3361    /// PARTITION BY expressions
3362    pub partition_by: Option<Vec<Expression>>,
3363    /// ORDER BY expressions
3364    pub order_by: Option<Vec<Ordered>>,
3365    /// MEASURES definitions
3366    pub measures: Option<Vec<MatchRecognizeMeasure>>,
3367    /// Row semantics (ONE ROW PER MATCH, ALL ROWS PER MATCH, etc.)
3368    pub rows: Option<MatchRecognizeRows>,
3369    /// AFTER MATCH SKIP behavior
3370    pub after: Option<MatchRecognizeAfter>,
3371    /// PATTERN definition (stored as raw string for complex regex patterns)
3372    pub pattern: Option<String>,
3373    /// DEFINE clauses (pattern variable definitions)
3374    pub define: Option<Vec<(Identifier, Expression)>>,
3375    /// Optional alias for the result
3376    pub alias: Option<Identifier>,
3377    /// Whether AS keyword was explicitly present before alias
3378    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3379    pub alias_explicit_as: bool,
3380}
3381
3382/// MEASURES expression with optional RUNNING/FINAL semantics
3383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3384#[cfg_attr(feature = "bindings", derive(TS))]
3385#[cfg_attr(feature = "bindings", ts(export))]
3386pub struct MatchRecognizeMeasure {
3387    /// The measure expression
3388    pub this: Expression,
3389    /// RUNNING or FINAL semantics (Snowflake-specific)
3390    pub window_frame: Option<MatchRecognizeSemantics>,
3391}
3392
3393/// Semantics for MEASURES in MATCH_RECOGNIZE
3394#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3395#[cfg_attr(feature = "bindings", derive(TS))]
3396#[cfg_attr(feature = "bindings", ts(export))]
3397pub enum MatchRecognizeSemantics {
3398    Running,
3399    Final,
3400}
3401
3402/// Row output semantics for MATCH_RECOGNIZE
3403#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3404#[cfg_attr(feature = "bindings", derive(TS))]
3405#[cfg_attr(feature = "bindings", ts(export))]
3406pub enum MatchRecognizeRows {
3407    OneRowPerMatch,
3408    AllRowsPerMatch,
3409    AllRowsPerMatchShowEmptyMatches,
3410    AllRowsPerMatchOmitEmptyMatches,
3411    AllRowsPerMatchWithUnmatchedRows,
3412}
3413
3414/// AFTER MATCH SKIP behavior
3415#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3416#[cfg_attr(feature = "bindings", derive(TS))]
3417#[cfg_attr(feature = "bindings", ts(export))]
3418pub enum MatchRecognizeAfter {
3419    PastLastRow,
3420    ToNextRow,
3421    ToFirst(Identifier),
3422    ToLast(Identifier),
3423}
3424
3425/// Represent a LIMIT clause that restricts the number of returned rows.
3426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3427#[cfg_attr(feature = "bindings", derive(TS))]
3428pub struct Limit {
3429    /// The limit count expression.
3430    pub this: Expression,
3431    /// Whether PERCENT modifier is present (DuckDB: LIMIT 10 PERCENT)
3432    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3433    pub percent: bool,
3434    /// Comments from before the LIMIT keyword (emitted after the limit value)
3435    #[serde(default)]
3436    #[serde(skip_serializing_if = "Vec::is_empty")]
3437    pub comments: Vec<String>,
3438}
3439
3440/// OFFSET clause
3441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3442#[cfg_attr(feature = "bindings", derive(TS))]
3443pub struct Offset {
3444    pub this: Expression,
3445    /// Whether ROW/ROWS keyword was used (SQL standard syntax)
3446    #[serde(skip_serializing_if = "Option::is_none", default)]
3447    pub rows: Option<bool>,
3448}
3449
3450/// TOP clause (SQL Server)
3451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3452#[cfg_attr(feature = "bindings", derive(TS))]
3453pub struct Top {
3454    pub this: Expression,
3455    pub percent: bool,
3456    pub with_ties: bool,
3457    /// Whether the expression was parenthesized: TOP (10) vs TOP 10
3458    #[serde(default)]
3459    pub parenthesized: bool,
3460}
3461
3462/// FETCH FIRST/NEXT clause (SQL standard)
3463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3464#[cfg_attr(feature = "bindings", derive(TS))]
3465pub struct Fetch {
3466    /// FIRST or NEXT
3467    pub direction: String,
3468    /// Count expression (optional)
3469    pub count: Option<Expression>,
3470    /// PERCENT modifier
3471    pub percent: bool,
3472    /// ROWS or ROW keyword present
3473    pub rows: bool,
3474    /// WITH TIES modifier
3475    pub with_ties: bool,
3476}
3477
3478/// Represent a QUALIFY clause for filtering on window function results.
3479///
3480/// Supported by Snowflake, BigQuery, DuckDB, and Databricks. The predicate
3481/// typically references a window function (e.g.
3482/// `QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY ts DESC) = 1`).
3483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3484#[cfg_attr(feature = "bindings", derive(TS))]
3485pub struct Qualify {
3486    /// The filter predicate over window function results.
3487    pub this: Expression,
3488}
3489
3490/// SAMPLE / TABLESAMPLE clause
3491#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3492#[cfg_attr(feature = "bindings", derive(TS))]
3493pub struct Sample {
3494    pub method: SampleMethod,
3495    pub size: Expression,
3496    pub seed: Option<Expression>,
3497    /// ClickHouse OFFSET expression after SAMPLE size
3498    #[serde(default)]
3499    pub offset: Option<Expression>,
3500    /// Whether the unit comes after the size (e.g., "100 ROWS" vs "ROW 100")
3501    pub unit_after_size: bool,
3502    /// Whether the keyword was SAMPLE (true) or TABLESAMPLE (false)
3503    #[serde(default)]
3504    pub use_sample_keyword: bool,
3505    /// Whether the method was explicitly specified (BERNOULLI, SYSTEM, etc.)
3506    #[serde(default)]
3507    pub explicit_method: bool,
3508    /// Whether the method keyword appeared before the size (TABLESAMPLE BERNOULLI (10))
3509    #[serde(default)]
3510    pub method_before_size: bool,
3511    /// Whether SEED keyword was used (true) or REPEATABLE (false)
3512    #[serde(default)]
3513    pub use_seed_keyword: bool,
3514    /// BUCKET numerator for Hive bucket sampling (BUCKET 1 OUT OF 5)
3515    pub bucket_numerator: Option<Box<Expression>>,
3516    /// BUCKET denominator (the 5 in BUCKET 1 OUT OF 5)
3517    pub bucket_denominator: Option<Box<Expression>>,
3518    /// BUCKET field for ON clause (BUCKET 1 OUT OF 5 ON x)
3519    pub bucket_field: Option<Box<Expression>>,
3520    /// Whether this is a DuckDB USING SAMPLE clause (vs SAMPLE/TABLESAMPLE)
3521    #[serde(default)]
3522    pub is_using_sample: bool,
3523    /// Whether the unit was explicitly PERCENT (vs ROWS)
3524    #[serde(default)]
3525    pub is_percent: bool,
3526    /// Whether to suppress method output (for cross-dialect transpilation)
3527    #[serde(default)]
3528    pub suppress_method_output: bool,
3529}
3530
3531/// Sample method
3532#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3533#[cfg_attr(feature = "bindings", derive(TS))]
3534pub enum SampleMethod {
3535    Bernoulli,
3536    System,
3537    Block,
3538    Row,
3539    Percent,
3540    /// Hive bucket sampling
3541    Bucket,
3542    /// DuckDB reservoir sampling
3543    Reservoir,
3544}
3545
3546/// Named window definition (WINDOW w AS (...))
3547#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3548#[cfg_attr(feature = "bindings", derive(TS))]
3549pub struct NamedWindow {
3550    pub name: Identifier,
3551    pub spec: Over,
3552}
3553
3554/// Represent a WITH clause containing one or more Common Table Expressions (CTEs).
3555///
3556/// When `recursive` is true, the clause is `WITH RECURSIVE`, enabling CTEs
3557/// that reference themselves. Each CTE is defined in the `ctes` vector and
3558/// can be referenced by name in subsequent CTEs and in the main query body.
3559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3560#[cfg_attr(feature = "bindings", derive(TS))]
3561pub struct With {
3562    /// The list of CTE definitions, in order.
3563    pub ctes: Vec<Cte>,
3564    /// Whether the WITH RECURSIVE keyword was used.
3565    pub recursive: bool,
3566    /// Leading comments before the statement
3567    #[serde(default)]
3568    pub leading_comments: Vec<String>,
3569    /// SEARCH/CYCLE clause for recursive CTEs (PostgreSQL)
3570    #[serde(default, skip_serializing_if = "Option::is_none")]
3571    pub search: Option<Box<Expression>>,
3572}
3573
3574/// Represent a single Common Table Expression definition.
3575///
3576/// A CTE has a name (`alias`), an optional column list, and a body query.
3577/// The `materialized` field maps to PostgreSQL's `MATERIALIZED` /
3578/// `NOT MATERIALIZED` hints. ClickHouse supports an inverted syntax where
3579/// the expression comes before the alias (`alias_first`).
3580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3581#[cfg_attr(feature = "bindings", derive(TS))]
3582pub struct Cte {
3583    /// The CTE name.
3584    pub alias: Identifier,
3585    /// The CTE body (typically a SELECT, UNION, etc.).
3586    pub this: Expression,
3587    /// Optional column alias list: `cte_name(c1, c2) AS (...)`.
3588    pub columns: Vec<Identifier>,
3589    /// `Some(true)` = MATERIALIZED, `Some(false)` = NOT MATERIALIZED, `None` = unspecified.
3590    pub materialized: Option<bool>,
3591    /// USING KEY (columns) for DuckDB recursive CTEs
3592    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3593    pub key_expressions: Vec<Identifier>,
3594    /// ClickHouse supports expression-first WITH items: WITH <expr> AS <alias>
3595    #[serde(default)]
3596    pub alias_first: bool,
3597    /// Comments associated with this CTE (placed after alias name, before AS)
3598    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3599    pub comments: Vec<String>,
3600}
3601
3602/// Window specification
3603#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3604#[cfg_attr(feature = "bindings", derive(TS))]
3605pub struct WindowSpec {
3606    pub partition_by: Vec<Expression>,
3607    pub order_by: Vec<Ordered>,
3608    pub frame: Option<WindowFrame>,
3609}
3610
3611/// OVER clause
3612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3613#[cfg_attr(feature = "bindings", derive(TS))]
3614pub struct Over {
3615    /// Named window reference (e.g., OVER w or OVER (w ORDER BY x))
3616    pub window_name: Option<Identifier>,
3617    pub partition_by: Vec<Expression>,
3618    pub order_by: Vec<Ordered>,
3619    pub frame: Option<WindowFrame>,
3620    pub alias: Option<Identifier>,
3621}
3622
3623/// Window frame
3624#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3625#[cfg_attr(feature = "bindings", derive(TS))]
3626pub struct WindowFrame {
3627    pub kind: WindowFrameKind,
3628    pub start: WindowFrameBound,
3629    pub end: Option<WindowFrameBound>,
3630    pub exclude: Option<WindowFrameExclude>,
3631    /// Original text of the frame kind keyword (preserves input case, e.g. "range")
3632    #[serde(default, skip_serializing_if = "Option::is_none")]
3633    pub kind_text: Option<String>,
3634    /// Original text of the start bound side keyword (e.g. "preceding")
3635    #[serde(default, skip_serializing_if = "Option::is_none")]
3636    pub start_side_text: Option<String>,
3637    /// Original text of the end bound side keyword
3638    #[serde(default, skip_serializing_if = "Option::is_none")]
3639    pub end_side_text: Option<String>,
3640}
3641
3642#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3643#[cfg_attr(feature = "bindings", derive(TS))]
3644pub enum WindowFrameKind {
3645    Rows,
3646    Range,
3647    Groups,
3648}
3649
3650/// EXCLUDE clause for window frames
3651#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
3652#[cfg_attr(feature = "bindings", derive(TS))]
3653pub enum WindowFrameExclude {
3654    CurrentRow,
3655    Group,
3656    Ties,
3657    NoOthers,
3658}
3659
3660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3661#[cfg_attr(feature = "bindings", derive(TS))]
3662pub enum WindowFrameBound {
3663    CurrentRow,
3664    UnboundedPreceding,
3665    UnboundedFollowing,
3666    Preceding(Box<Expression>),
3667    Following(Box<Expression>),
3668    /// Bare PRECEDING without value (inverted syntax: just "PRECEDING")
3669    BarePreceding,
3670    /// Bare FOLLOWING without value (inverted syntax: just "FOLLOWING")
3671    BareFollowing,
3672    /// Bare numeric bound without PRECEDING/FOLLOWING (e.g., RANGE BETWEEN 1 AND 3)
3673    Value(Box<Expression>),
3674}
3675
3676/// Struct field with optional OPTIONS clause (BigQuery) and COMMENT (Spark/Databricks)
3677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3678#[cfg_attr(feature = "bindings", derive(TS))]
3679pub struct StructField {
3680    pub name: String,
3681    pub data_type: DataType,
3682    #[serde(default, skip_serializing_if = "Vec::is_empty")]
3683    pub options: Vec<Expression>,
3684    #[serde(default, skip_serializing_if = "Option::is_none")]
3685    pub comment: Option<String>,
3686}
3687
3688impl StructField {
3689    /// Create a new struct field without options
3690    pub fn new(name: String, data_type: DataType) -> Self {
3691        Self {
3692            name,
3693            data_type,
3694            options: Vec::new(),
3695            comment: None,
3696        }
3697    }
3698
3699    /// Create a new struct field with options
3700    pub fn with_options(name: String, data_type: DataType, options: Vec<Expression>) -> Self {
3701        Self {
3702            name,
3703            data_type,
3704            options,
3705            comment: None,
3706        }
3707    }
3708
3709    /// Create a new struct field with options and comment
3710    pub fn with_options_and_comment(
3711        name: String,
3712        data_type: DataType,
3713        options: Vec<Expression>,
3714        comment: Option<String>,
3715    ) -> Self {
3716        Self {
3717            name,
3718            data_type,
3719            options,
3720            comment,
3721        }
3722    }
3723}
3724
3725/// Enumerate all SQL data types recognized by the parser.
3726///
3727/// Covers standard SQL types (BOOLEAN, INT, VARCHAR, TIMESTAMP, etc.) as well
3728/// as dialect-specific types (JSONB, VECTOR, OBJECT, etc.). Parametric types
3729/// like ARRAY, MAP, and STRUCT are represented with nested [`DataType`] fields.
3730///
3731/// This enum is used in CAST expressions, column definitions, function return
3732/// types, and anywhere a data type specification appears in SQL.
3733///
3734/// Types that do not match any known variant fall through to `Custom { name }`,
3735/// preserving the original type name for round-trip fidelity.
3736#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3737#[cfg_attr(feature = "bindings", derive(TS))]
3738#[serde(tag = "data_type", rename_all = "snake_case")]
3739pub enum DataType {
3740    // Numeric
3741    Boolean,
3742    TinyInt {
3743        length: Option<u32>,
3744    },
3745    SmallInt {
3746        length: Option<u32>,
3747    },
3748    /// Int type with optional length. `integer_spelling` indicates whether the original
3749    /// type was spelled as `INTEGER` (true) vs `INT` (false), used for certain dialects
3750    /// like Databricks that preserve the original spelling in specific contexts (e.g., ?:: syntax).
3751    Int {
3752        length: Option<u32>,
3753        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3754        integer_spelling: bool,
3755    },
3756    BigInt {
3757        length: Option<u32>,
3758    },
3759    /// Float type with optional precision and scale. `real_spelling` indicates whether the original
3760    /// type was spelled as `REAL` (true) vs `FLOAT` (false), used for dialects like Redshift that
3761    /// preserve the original spelling.
3762    Float {
3763        precision: Option<u32>,
3764        scale: Option<u32>,
3765        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3766        real_spelling: bool,
3767    },
3768    Double {
3769        precision: Option<u32>,
3770        scale: Option<u32>,
3771    },
3772    Decimal {
3773        precision: Option<u32>,
3774        scale: Option<u32>,
3775    },
3776
3777    // String
3778    Char {
3779        length: Option<u32>,
3780    },
3781    /// VarChar type with optional length. `parenthesized_length` indicates whether the length
3782    /// was wrapped in extra parentheses (Hive: `VARCHAR((50))` inside STRUCT definitions).
3783    VarChar {
3784        length: Option<u32>,
3785        #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3786        parenthesized_length: bool,
3787    },
3788    /// String type with optional max length (BigQuery STRING(n))
3789    String {
3790        length: Option<u32>,
3791    },
3792    Text,
3793    /// TEXT with optional length: TEXT(n) - used by MySQL, SQLite, DuckDB, etc.
3794    TextWithLength {
3795        length: u32,
3796    },
3797
3798    // Binary
3799    Binary {
3800        length: Option<u32>,
3801    },
3802    VarBinary {
3803        length: Option<u32>,
3804    },
3805    Blob,
3806
3807    // Bit
3808    Bit {
3809        length: Option<u32>,
3810    },
3811    VarBit {
3812        length: Option<u32>,
3813    },
3814
3815    // Date/Time
3816    Date,
3817    Time {
3818        precision: Option<u32>,
3819        #[serde(default)]
3820        timezone: bool,
3821    },
3822    Timestamp {
3823        precision: Option<u32>,
3824        timezone: bool,
3825    },
3826    Interval {
3827        unit: Option<String>,
3828        /// For range intervals like INTERVAL DAY TO HOUR
3829        #[serde(default, skip_serializing_if = "Option::is_none")]
3830        to: Option<String>,
3831    },
3832
3833    // JSON
3834    Json,
3835    JsonB,
3836
3837    // UUID
3838    Uuid,
3839
3840    // Array
3841    Array {
3842        element_type: Box<DataType>,
3843        /// Optional dimension size for PostgreSQL (e.g., [3] in INT[3])
3844        #[serde(default, skip_serializing_if = "Option::is_none")]
3845        dimension: Option<u32>,
3846    },
3847
3848    /// List type (Materialize): INT LIST, TEXT LIST LIST
3849    /// Uses postfix LIST syntax instead of ARRAY<T>
3850    List {
3851        element_type: Box<DataType>,
3852    },
3853
3854    // Struct/Map
3855    // nested: true means parenthesized syntax STRUCT(name TYPE, ...) (DuckDB/Presto/ROW)
3856    // nested: false means angle-bracket syntax STRUCT<name TYPE, ...> (BigQuery)
3857    Struct {
3858        fields: Vec<StructField>,
3859        nested: bool,
3860    },
3861    Map {
3862        key_type: Box<DataType>,
3863        value_type: Box<DataType>,
3864    },
3865
3866    // Enum type (DuckDB): ENUM('RED', 'GREEN', 'BLUE')
3867    Enum {
3868        values: Vec<String>,
3869        #[serde(default, skip_serializing_if = "Vec::is_empty")]
3870        assignments: Vec<Option<String>>,
3871    },
3872
3873    // Set type (MySQL): SET('a', 'b', 'c')
3874    Set {
3875        values: Vec<String>,
3876    },
3877
3878    // Union type (DuckDB): UNION(num INT, str TEXT)
3879    Union {
3880        fields: Vec<(String, DataType)>,
3881    },
3882
3883    // Vector (Snowflake / SingleStore)
3884    Vector {
3885        #[serde(default)]
3886        element_type: Option<Box<DataType>>,
3887        dimension: Option<u32>,
3888    },
3889
3890    // Object (Snowflake structured type)
3891    // fields: Vec of (field_name, field_type, not_null)
3892    Object {
3893        fields: Vec<(String, DataType, bool)>,
3894        modifier: Option<String>,
3895    },
3896
3897    // Nullable wrapper (ClickHouse): Nullable(String), Nullable(Int32)
3898    Nullable {
3899        inner: Box<DataType>,
3900    },
3901
3902    // Custom/User-defined
3903    Custom {
3904        name: String,
3905    },
3906
3907    // Spatial types
3908    Geometry {
3909        subtype: Option<String>,
3910        srid: Option<u32>,
3911    },
3912    Geography {
3913        subtype: Option<String>,
3914        srid: Option<u32>,
3915    },
3916
3917    // Character Set (for CONVERT USING in MySQL)
3918    // Renders as CHAR CHARACTER SET {name} in cast target
3919    CharacterSet {
3920        name: String,
3921    },
3922
3923    // Unknown
3924    Unknown,
3925}
3926
3927/// Array expression
3928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3929#[cfg_attr(feature = "bindings", derive(TS))]
3930#[cfg_attr(feature = "bindings", ts(rename = "SqlArray"))]
3931pub struct Array {
3932    pub expressions: Vec<Expression>,
3933}
3934
3935/// Struct expression
3936#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3937#[cfg_attr(feature = "bindings", derive(TS))]
3938pub struct Struct {
3939    pub fields: Vec<(Option<String>, Expression)>,
3940}
3941
3942/// Tuple expression
3943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3944#[cfg_attr(feature = "bindings", derive(TS))]
3945pub struct Tuple {
3946    pub expressions: Vec<Expression>,
3947}
3948
3949/// Interval expression
3950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3951#[cfg_attr(feature = "bindings", derive(TS))]
3952pub struct Interval {
3953    /// The value expression (e.g., '1', 5, column_ref)
3954    pub this: Option<Expression>,
3955    /// The unit specification (optional - can be None, a simple unit, a span, or an expression)
3956    pub unit: Option<IntervalUnitSpec>,
3957}
3958
3959/// Specification for interval unit - can be a simple unit, a span (HOUR TO SECOND), or an expression
3960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3961#[cfg_attr(feature = "bindings", derive(TS))]
3962#[serde(tag = "type", rename_all = "snake_case")]
3963pub enum IntervalUnitSpec {
3964    /// Simple interval unit (YEAR, MONTH, DAY, etc.)
3965    Simple {
3966        unit: IntervalUnit,
3967        /// Whether to use plural form (e.g., DAYS vs DAY)
3968        use_plural: bool,
3969    },
3970    /// Interval span (e.g., HOUR TO SECOND)
3971    Span(IntervalSpan),
3972    /// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3973    /// The start and end can be expressions like function calls with precision
3974    ExprSpan(IntervalSpanExpr),
3975    /// Expression as unit (e.g., CURRENT_DATE, CAST(GETDATE() AS DATE))
3976    Expr(Box<Expression>),
3977}
3978
3979/// Interval span for ranges like HOUR TO SECOND
3980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3981#[cfg_attr(feature = "bindings", derive(TS))]
3982pub struct IntervalSpan {
3983    /// Start unit (e.g., HOUR)
3984    pub this: IntervalUnit,
3985    /// End unit (e.g., SECOND)
3986    pub expression: IntervalUnit,
3987}
3988
3989/// Expression-based interval span for Oracle (e.g., DAY(9) TO SECOND(3))
3990/// Unlike IntervalSpan, this uses expressions to represent units with optional precision
3991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3992#[cfg_attr(feature = "bindings", derive(TS))]
3993pub struct IntervalSpanExpr {
3994    /// Start unit expression (e.g., Var("DAY") or Anonymous("DAY", [9]))
3995    pub this: Box<Expression>,
3996    /// End unit expression (e.g., Var("SECOND") or Anonymous("SECOND", [3]))
3997    pub expression: Box<Expression>,
3998}
3999
4000#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4001#[cfg_attr(feature = "bindings", derive(TS))]
4002pub enum IntervalUnit {
4003    Year,
4004    Quarter,
4005    Month,
4006    Week,
4007    Day,
4008    Hour,
4009    Minute,
4010    Second,
4011    Millisecond,
4012    Microsecond,
4013    Nanosecond,
4014}
4015
4016/// SQL Command (COMMIT, ROLLBACK, BEGIN, etc.)
4017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4018#[cfg_attr(feature = "bindings", derive(TS))]
4019pub struct Command {
4020    /// The command text (e.g., "ROLLBACK", "COMMIT", "BEGIN")
4021    pub this: String,
4022}
4023
4024/// EXEC/EXECUTE statement (TSQL stored procedure call)
4025/// Syntax: EXEC [schema.]procedure_name [@param=value, ...]
4026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4027#[cfg_attr(feature = "bindings", derive(TS))]
4028pub struct ExecuteStatement {
4029    /// The procedure name (can be qualified: schema.proc_name)
4030    pub this: Expression,
4031    /// Named parameters: @param=value pairs
4032    #[serde(default)]
4033    pub parameters: Vec<ExecuteParameter>,
4034}
4035
4036/// Named parameter in EXEC statement: @name=value
4037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4038#[cfg_attr(feature = "bindings", derive(TS))]
4039pub struct ExecuteParameter {
4040    /// Parameter name (including @)
4041    pub name: String,
4042    /// Parameter value
4043    pub value: Expression,
4044}
4045
4046/// KILL statement (MySQL/MariaDB)
4047/// KILL [CONNECTION | QUERY] <id>
4048#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4049#[cfg_attr(feature = "bindings", derive(TS))]
4050pub struct Kill {
4051    /// The target (process ID or connection ID)
4052    pub this: Expression,
4053    /// Optional kind: "CONNECTION" or "QUERY"
4054    pub kind: Option<String>,
4055}
4056
4057/// Raw/unparsed SQL
4058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4059#[cfg_attr(feature = "bindings", derive(TS))]
4060pub struct Raw {
4061    pub sql: String,
4062}
4063
4064// ============================================================================
4065// Function expression types
4066// ============================================================================
4067
4068/// Generic unary function (takes a single argument)
4069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4070#[cfg_attr(feature = "bindings", derive(TS))]
4071pub struct UnaryFunc {
4072    pub this: Expression,
4073    /// Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
4074    #[serde(skip_serializing_if = "Option::is_none", default)]
4075    pub original_name: Option<String>,
4076}
4077
4078impl UnaryFunc {
4079    /// Create a new UnaryFunc with no original_name
4080    pub fn new(this: Expression) -> Self {
4081        Self {
4082            this,
4083            original_name: None,
4084        }
4085    }
4086
4087    /// Create a new UnaryFunc with an original name for round-trip preservation
4088    pub fn with_name(this: Expression, name: String) -> Self {
4089        Self {
4090            this,
4091            original_name: Some(name),
4092        }
4093    }
4094}
4095
4096/// CHAR/CHR function with multiple args and optional USING charset
4097/// e.g., CHAR(77, 77.3, '77.3' USING utf8mb4)
4098/// e.g., CHR(187 USING NCHAR_CS) -- Oracle
4099#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4100#[cfg_attr(feature = "bindings", derive(TS))]
4101pub struct CharFunc {
4102    pub args: Vec<Expression>,
4103    #[serde(skip_serializing_if = "Option::is_none", default)]
4104    pub charset: Option<String>,
4105    /// Original function name (CHAR or CHR), defaults to CHAR
4106    #[serde(skip_serializing_if = "Option::is_none", default)]
4107    pub name: Option<String>,
4108}
4109
4110/// Generic binary function (takes two arguments)
4111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4112#[cfg_attr(feature = "bindings", derive(TS))]
4113pub struct BinaryFunc {
4114    pub this: Expression,
4115    pub expression: Expression,
4116    /// Original function name for round-trip preservation (e.g., NVL vs IFNULL)
4117    #[serde(skip_serializing_if = "Option::is_none", default)]
4118    pub original_name: Option<String>,
4119}
4120
4121/// Variable argument function
4122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4123#[cfg_attr(feature = "bindings", derive(TS))]
4124pub struct VarArgFunc {
4125    pub expressions: Vec<Expression>,
4126    /// Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
4127    #[serde(skip_serializing_if = "Option::is_none", default)]
4128    pub original_name: Option<String>,
4129}
4130
4131/// CONCAT_WS function
4132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4133#[cfg_attr(feature = "bindings", derive(TS))]
4134pub struct ConcatWs {
4135    pub separator: Expression,
4136    pub expressions: Vec<Expression>,
4137}
4138
4139/// SUBSTRING function
4140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4141#[cfg_attr(feature = "bindings", derive(TS))]
4142pub struct SubstringFunc {
4143    pub this: Expression,
4144    pub start: Expression,
4145    pub length: Option<Expression>,
4146    /// Whether SQL standard FROM/FOR syntax was used (true) vs comma-separated (false)
4147    #[serde(default)]
4148    pub from_for_syntax: bool,
4149}
4150
4151/// OVERLAY function - OVERLAY(string PLACING replacement FROM position [FOR length])
4152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4153#[cfg_attr(feature = "bindings", derive(TS))]
4154pub struct OverlayFunc {
4155    pub this: Expression,
4156    pub replacement: Expression,
4157    pub from: Expression,
4158    pub length: Option<Expression>,
4159}
4160
4161/// TRIM function
4162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4163#[cfg_attr(feature = "bindings", derive(TS))]
4164pub struct TrimFunc {
4165    pub this: Expression,
4166    pub characters: Option<Expression>,
4167    pub position: TrimPosition,
4168    /// Whether SQL standard syntax was used (TRIM(BOTH chars FROM str)) vs function syntax (TRIM(str))
4169    #[serde(default)]
4170    pub sql_standard_syntax: bool,
4171    /// Whether the position was explicitly specified (BOTH/LEADING/TRAILING) vs defaulted
4172    #[serde(default)]
4173    pub position_explicit: bool,
4174}
4175
4176#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4177#[cfg_attr(feature = "bindings", derive(TS))]
4178pub enum TrimPosition {
4179    Both,
4180    Leading,
4181    Trailing,
4182}
4183
4184/// REPLACE function
4185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4186#[cfg_attr(feature = "bindings", derive(TS))]
4187pub struct ReplaceFunc {
4188    pub this: Expression,
4189    pub old: Expression,
4190    pub new: Expression,
4191}
4192
4193/// LEFT/RIGHT function
4194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4195#[cfg_attr(feature = "bindings", derive(TS))]
4196pub struct LeftRightFunc {
4197    pub this: Expression,
4198    pub length: Expression,
4199}
4200
4201/// REPEAT function
4202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4203#[cfg_attr(feature = "bindings", derive(TS))]
4204pub struct RepeatFunc {
4205    pub this: Expression,
4206    pub times: Expression,
4207}
4208
4209/// LPAD/RPAD function
4210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4211#[cfg_attr(feature = "bindings", derive(TS))]
4212pub struct PadFunc {
4213    pub this: Expression,
4214    pub length: Expression,
4215    pub fill: Option<Expression>,
4216}
4217
4218/// SPLIT function
4219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4220#[cfg_attr(feature = "bindings", derive(TS))]
4221pub struct SplitFunc {
4222    pub this: Expression,
4223    pub delimiter: Expression,
4224}
4225
4226/// REGEXP_LIKE function
4227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4228#[cfg_attr(feature = "bindings", derive(TS))]
4229pub struct RegexpFunc {
4230    pub this: Expression,
4231    pub pattern: Expression,
4232    pub flags: Option<Expression>,
4233}
4234
4235/// REGEXP_REPLACE function
4236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4237#[cfg_attr(feature = "bindings", derive(TS))]
4238pub struct RegexpReplaceFunc {
4239    pub this: Expression,
4240    pub pattern: Expression,
4241    pub replacement: Expression,
4242    pub flags: Option<Expression>,
4243}
4244
4245/// REGEXP_EXTRACT function
4246#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4247#[cfg_attr(feature = "bindings", derive(TS))]
4248pub struct RegexpExtractFunc {
4249    pub this: Expression,
4250    pub pattern: Expression,
4251    pub group: Option<Expression>,
4252}
4253
4254/// ROUND function
4255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4256#[cfg_attr(feature = "bindings", derive(TS))]
4257pub struct RoundFunc {
4258    pub this: Expression,
4259    pub decimals: Option<Expression>,
4260}
4261
4262/// FLOOR function with optional scale and time unit (Druid: FLOOR(time TO unit))
4263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4264#[cfg_attr(feature = "bindings", derive(TS))]
4265pub struct FloorFunc {
4266    pub this: Expression,
4267    pub scale: Option<Expression>,
4268    /// Time unit for Druid-style FLOOR(time TO unit) syntax
4269    #[serde(skip_serializing_if = "Option::is_none", default)]
4270    pub to: Option<Expression>,
4271}
4272
4273/// CEIL function with optional decimals and time unit (Druid: CEIL(time TO unit))
4274#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4275#[cfg_attr(feature = "bindings", derive(TS))]
4276pub struct CeilFunc {
4277    pub this: Expression,
4278    #[serde(skip_serializing_if = "Option::is_none", default)]
4279    pub decimals: Option<Expression>,
4280    /// Time unit for Druid-style CEIL(time TO unit) syntax
4281    #[serde(skip_serializing_if = "Option::is_none", default)]
4282    pub to: Option<Expression>,
4283}
4284
4285/// LOG function
4286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4287#[cfg_attr(feature = "bindings", derive(TS))]
4288pub struct LogFunc {
4289    pub this: Expression,
4290    pub base: Option<Expression>,
4291}
4292
4293/// CURRENT_DATE (no arguments)
4294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4295#[cfg_attr(feature = "bindings", derive(TS))]
4296pub struct CurrentDate;
4297
4298/// CURRENT_TIME
4299#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4300#[cfg_attr(feature = "bindings", derive(TS))]
4301pub struct CurrentTime {
4302    pub precision: Option<u32>,
4303}
4304
4305/// CURRENT_TIMESTAMP
4306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4307#[cfg_attr(feature = "bindings", derive(TS))]
4308pub struct CurrentTimestamp {
4309    pub precision: Option<u32>,
4310    /// If true, generate SYSDATE instead of CURRENT_TIMESTAMP (Oracle-specific)
4311    #[serde(default)]
4312    pub sysdate: bool,
4313}
4314
4315/// CURRENT_TIMESTAMP_LTZ - Snowflake local timezone timestamp
4316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4317#[cfg_attr(feature = "bindings", derive(TS))]
4318pub struct CurrentTimestampLTZ {
4319    pub precision: Option<u32>,
4320}
4321
4322/// AT TIME ZONE expression for timezone conversion
4323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4324#[cfg_attr(feature = "bindings", derive(TS))]
4325pub struct AtTimeZone {
4326    /// The expression to convert
4327    pub this: Expression,
4328    /// The target timezone
4329    pub zone: Expression,
4330}
4331
4332/// DATE_ADD / DATE_SUB function
4333#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4334#[cfg_attr(feature = "bindings", derive(TS))]
4335pub struct DateAddFunc {
4336    pub this: Expression,
4337    pub interval: Expression,
4338    pub unit: IntervalUnit,
4339}
4340
4341/// DATEDIFF function
4342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4343#[cfg_attr(feature = "bindings", derive(TS))]
4344pub struct DateDiffFunc {
4345    pub this: Expression,
4346    pub expression: Expression,
4347    pub unit: Option<IntervalUnit>,
4348}
4349
4350/// DATE_TRUNC function
4351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4352#[cfg_attr(feature = "bindings", derive(TS))]
4353pub struct DateTruncFunc {
4354    pub this: Expression,
4355    pub unit: DateTimeField,
4356}
4357
4358/// EXTRACT function
4359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4360#[cfg_attr(feature = "bindings", derive(TS))]
4361pub struct ExtractFunc {
4362    pub this: Expression,
4363    pub field: DateTimeField,
4364}
4365
4366#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4367#[cfg_attr(feature = "bindings", derive(TS))]
4368pub enum DateTimeField {
4369    Year,
4370    Month,
4371    Day,
4372    Hour,
4373    Minute,
4374    Second,
4375    Millisecond,
4376    Microsecond,
4377    DayOfWeek,
4378    DayOfYear,
4379    Week,
4380    /// Week with a modifier like WEEK(monday), WEEK(sunday)
4381    WeekWithModifier(String),
4382    Quarter,
4383    Epoch,
4384    Timezone,
4385    TimezoneHour,
4386    TimezoneMinute,
4387    Date,
4388    Time,
4389    /// Custom datetime field for dialect-specific or arbitrary fields
4390    Custom(String),
4391}
4392
4393/// TO_DATE function
4394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4395#[cfg_attr(feature = "bindings", derive(TS))]
4396pub struct ToDateFunc {
4397    pub this: Expression,
4398    pub format: Option<Expression>,
4399}
4400
4401/// TO_TIMESTAMP function
4402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4403#[cfg_attr(feature = "bindings", derive(TS))]
4404pub struct ToTimestampFunc {
4405    pub this: Expression,
4406    pub format: Option<Expression>,
4407}
4408
4409/// IF function
4410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4411#[cfg_attr(feature = "bindings", derive(TS))]
4412pub struct IfFunc {
4413    pub condition: Expression,
4414    pub true_value: Expression,
4415    pub false_value: Option<Expression>,
4416    /// Original function name (IF, IFF, IIF) for round-trip preservation
4417    #[serde(skip_serializing_if = "Option::is_none", default)]
4418    pub original_name: Option<String>,
4419}
4420
4421/// NVL2 function
4422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4423#[cfg_attr(feature = "bindings", derive(TS))]
4424pub struct Nvl2Func {
4425    pub this: Expression,
4426    pub true_value: Expression,
4427    pub false_value: Expression,
4428}
4429
4430// ============================================================================
4431// Typed Aggregate Function types
4432// ============================================================================
4433
4434/// Generic aggregate function base type
4435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4436#[cfg_attr(feature = "bindings", derive(TS))]
4437pub struct AggFunc {
4438    pub this: Expression,
4439    pub distinct: bool,
4440    pub filter: Option<Expression>,
4441    pub order_by: Vec<Ordered>,
4442    /// Original function name (case-preserving) when parsed from SQL
4443    #[serde(skip_serializing_if = "Option::is_none", default)]
4444    pub name: Option<String>,
4445    /// IGNORE NULLS (true) or RESPECT NULLS (false), None if not specified
4446    #[serde(skip_serializing_if = "Option::is_none", default)]
4447    pub ignore_nulls: Option<bool>,
4448    /// HAVING MAX/MIN expr inside aggregate (BigQuery syntax)
4449    /// e.g., ANY_VALUE(fruit HAVING MAX sold) - (expression, is_max: true for MAX, false for MIN)
4450    #[serde(skip_serializing_if = "Option::is_none", default)]
4451    pub having_max: Option<(Box<Expression>, bool)>,
4452    /// LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
4453    #[serde(skip_serializing_if = "Option::is_none", default)]
4454    pub limit: Option<Box<Expression>>,
4455}
4456
4457/// COUNT function with optional star
4458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4459#[cfg_attr(feature = "bindings", derive(TS))]
4460pub struct CountFunc {
4461    pub this: Option<Expression>,
4462    pub star: bool,
4463    pub distinct: bool,
4464    pub filter: Option<Expression>,
4465    /// IGNORE NULLS (true) or RESPECT NULLS (false)
4466    #[serde(default, skip_serializing_if = "Option::is_none")]
4467    pub ignore_nulls: Option<bool>,
4468    /// Original function name for case preservation (e.g., "count" or "COUNT")
4469    #[serde(default, skip_serializing_if = "Option::is_none")]
4470    pub original_name: Option<String>,
4471}
4472
4473/// GROUP_CONCAT function (MySQL style)
4474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4475#[cfg_attr(feature = "bindings", derive(TS))]
4476pub struct GroupConcatFunc {
4477    pub this: Expression,
4478    pub separator: Option<Expression>,
4479    pub order_by: Option<Vec<Ordered>>,
4480    pub distinct: bool,
4481    pub filter: Option<Expression>,
4482}
4483
4484/// STRING_AGG function (PostgreSQL/Standard SQL)
4485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4486#[cfg_attr(feature = "bindings", derive(TS))]
4487pub struct StringAggFunc {
4488    pub this: Expression,
4489    #[serde(default)]
4490    pub separator: Option<Expression>,
4491    #[serde(default)]
4492    pub order_by: Option<Vec<Ordered>>,
4493    #[serde(default)]
4494    pub distinct: bool,
4495    #[serde(default)]
4496    pub filter: Option<Expression>,
4497    /// BigQuery LIMIT inside STRING_AGG
4498    #[serde(default, skip_serializing_if = "Option::is_none")]
4499    pub limit: Option<Box<Expression>>,
4500}
4501
4502/// LISTAGG function (Oracle style)
4503#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4504#[cfg_attr(feature = "bindings", derive(TS))]
4505pub struct ListAggFunc {
4506    pub this: Expression,
4507    pub separator: Option<Expression>,
4508    pub on_overflow: Option<ListAggOverflow>,
4509    pub order_by: Option<Vec<Ordered>>,
4510    pub distinct: bool,
4511    pub filter: Option<Expression>,
4512}
4513
4514/// LISTAGG ON OVERFLOW behavior
4515#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4516#[cfg_attr(feature = "bindings", derive(TS))]
4517pub enum ListAggOverflow {
4518    Error,
4519    Truncate {
4520        filler: Option<Expression>,
4521        with_count: bool,
4522    },
4523}
4524
4525/// SUM_IF / COUNT_IF function
4526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4527#[cfg_attr(feature = "bindings", derive(TS))]
4528pub struct SumIfFunc {
4529    pub this: Expression,
4530    pub condition: Expression,
4531    pub filter: Option<Expression>,
4532}
4533
4534/// APPROX_PERCENTILE function
4535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4536#[cfg_attr(feature = "bindings", derive(TS))]
4537pub struct ApproxPercentileFunc {
4538    pub this: Expression,
4539    pub percentile: Expression,
4540    pub accuracy: Option<Expression>,
4541    pub filter: Option<Expression>,
4542}
4543
4544/// PERCENTILE_CONT / PERCENTILE_DISC function
4545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4546#[cfg_attr(feature = "bindings", derive(TS))]
4547pub struct PercentileFunc {
4548    pub this: Expression,
4549    pub percentile: Expression,
4550    pub order_by: Option<Vec<Ordered>>,
4551    pub filter: Option<Expression>,
4552}
4553
4554// ============================================================================
4555// Typed Window Function types
4556// ============================================================================
4557
4558/// ROW_NUMBER function (no arguments)
4559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4560#[cfg_attr(feature = "bindings", derive(TS))]
4561pub struct RowNumber;
4562
4563/// RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4564#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4565#[cfg_attr(feature = "bindings", derive(TS))]
4566pub struct Rank {
4567    /// DuckDB: RANK(ORDER BY col) - order by inside function
4568    #[serde(default, skip_serializing_if = "Option::is_none")]
4569    pub order_by: Option<Vec<Ordered>>,
4570    /// Oracle hypothetical rank: RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4571    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4572    pub args: Vec<Expression>,
4573}
4574
4575/// DENSE_RANK function (Oracle allows hypothetical args with WITHIN GROUP)
4576#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4577#[cfg_attr(feature = "bindings", derive(TS))]
4578pub struct DenseRank {
4579    /// Oracle hypothetical rank: DENSE_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4580    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4581    pub args: Vec<Expression>,
4582}
4583
4584/// NTILE function (DuckDB allows ORDER BY inside)
4585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4586#[cfg_attr(feature = "bindings", derive(TS))]
4587pub struct NTileFunc {
4588    /// num_buckets is optional to support Databricks NTILE() without arguments
4589    #[serde(default, skip_serializing_if = "Option::is_none")]
4590    pub num_buckets: Option<Expression>,
4591    /// DuckDB: NTILE(n ORDER BY col) - order by inside function
4592    #[serde(default, skip_serializing_if = "Option::is_none")]
4593    pub order_by: Option<Vec<Ordered>>,
4594}
4595
4596/// LEAD / LAG function
4597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4598#[cfg_attr(feature = "bindings", derive(TS))]
4599pub struct LeadLagFunc {
4600    pub this: Expression,
4601    pub offset: Option<Expression>,
4602    pub default: Option<Expression>,
4603    pub ignore_nulls: bool,
4604}
4605
4606/// FIRST_VALUE / LAST_VALUE function
4607#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4608#[cfg_attr(feature = "bindings", derive(TS))]
4609pub struct ValueFunc {
4610    pub this: Expression,
4611    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4612    #[serde(default, skip_serializing_if = "Option::is_none")]
4613    pub ignore_nulls: Option<bool>,
4614}
4615
4616/// NTH_VALUE function
4617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4618#[cfg_attr(feature = "bindings", derive(TS))]
4619pub struct NthValueFunc {
4620    pub this: Expression,
4621    pub offset: Expression,
4622    /// None = not specified, Some(true) = IGNORE NULLS, Some(false) = RESPECT NULLS
4623    #[serde(default, skip_serializing_if = "Option::is_none")]
4624    pub ignore_nulls: Option<bool>,
4625    /// Snowflake FROM FIRST / FROM LAST clause
4626    /// None = not specified, Some(true) = FROM FIRST, Some(false) = FROM LAST
4627    #[serde(default, skip_serializing_if = "Option::is_none")]
4628    pub from_first: Option<bool>,
4629}
4630
4631/// PERCENT_RANK function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4633#[cfg_attr(feature = "bindings", derive(TS))]
4634pub struct PercentRank {
4635    /// DuckDB: PERCENT_RANK(ORDER BY col) - order by inside function
4636    #[serde(default, skip_serializing_if = "Option::is_none")]
4637    pub order_by: Option<Vec<Ordered>>,
4638    /// Oracle hypothetical rank: PERCENT_RANK(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4639    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4640    pub args: Vec<Expression>,
4641}
4642
4643/// CUME_DIST function (DuckDB allows ORDER BY inside, Oracle allows hypothetical args with WITHIN GROUP)
4644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4645#[cfg_attr(feature = "bindings", derive(TS))]
4646pub struct CumeDist {
4647    /// DuckDB: CUME_DIST(ORDER BY col) - order by inside function
4648    #[serde(default, skip_serializing_if = "Option::is_none")]
4649    pub order_by: Option<Vec<Ordered>>,
4650    /// Oracle hypothetical rank: CUME_DIST(val1, val2, ...) WITHIN GROUP (ORDER BY ...)
4651    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4652    pub args: Vec<Expression>,
4653}
4654
4655// ============================================================================
4656// Additional String Function types
4657// ============================================================================
4658
4659/// POSITION/INSTR function
4660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4661#[cfg_attr(feature = "bindings", derive(TS))]
4662pub struct PositionFunc {
4663    pub substring: Expression,
4664    pub string: Expression,
4665    pub start: Option<Expression>,
4666}
4667
4668// ============================================================================
4669// Additional Math Function types
4670// ============================================================================
4671
4672/// RANDOM function (no arguments)
4673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4674#[cfg_attr(feature = "bindings", derive(TS))]
4675pub struct Random;
4676
4677/// RAND function (optional seed, or Teradata RANDOM(lower, upper))
4678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4679#[cfg_attr(feature = "bindings", derive(TS))]
4680pub struct Rand {
4681    pub seed: Option<Box<Expression>>,
4682    /// Teradata RANDOM lower bound
4683    #[serde(default)]
4684    pub lower: Option<Box<Expression>>,
4685    /// Teradata RANDOM upper bound
4686    #[serde(default)]
4687    pub upper: Option<Box<Expression>>,
4688}
4689
4690/// TRUNCATE / TRUNC function
4691#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4692#[cfg_attr(feature = "bindings", derive(TS))]
4693pub struct TruncateFunc {
4694    pub this: Expression,
4695    pub decimals: Option<Expression>,
4696}
4697
4698/// PI function (no arguments)
4699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4700#[cfg_attr(feature = "bindings", derive(TS))]
4701pub struct Pi;
4702
4703// ============================================================================
4704// Control Flow Function types
4705// ============================================================================
4706
4707/// DECODE function (Oracle style)
4708#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4709#[cfg_attr(feature = "bindings", derive(TS))]
4710pub struct DecodeFunc {
4711    pub this: Expression,
4712    pub search_results: Vec<(Expression, Expression)>,
4713    pub default: Option<Expression>,
4714}
4715
4716// ============================================================================
4717// Additional Date/Time Function types
4718// ============================================================================
4719
4720/// DATE_FORMAT / FORMAT_DATE function
4721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4722#[cfg_attr(feature = "bindings", derive(TS))]
4723pub struct DateFormatFunc {
4724    pub this: Expression,
4725    pub format: Expression,
4726}
4727
4728/// FROM_UNIXTIME function
4729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4730#[cfg_attr(feature = "bindings", derive(TS))]
4731pub struct FromUnixtimeFunc {
4732    pub this: Expression,
4733    pub format: Option<Expression>,
4734}
4735
4736/// UNIX_TIMESTAMP function
4737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4738#[cfg_attr(feature = "bindings", derive(TS))]
4739pub struct UnixTimestampFunc {
4740    pub this: Option<Expression>,
4741    pub format: Option<Expression>,
4742}
4743
4744/// MAKE_DATE function
4745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4746#[cfg_attr(feature = "bindings", derive(TS))]
4747pub struct MakeDateFunc {
4748    pub year: Expression,
4749    pub month: Expression,
4750    pub day: Expression,
4751}
4752
4753/// MAKE_TIMESTAMP function
4754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4755#[cfg_attr(feature = "bindings", derive(TS))]
4756pub struct MakeTimestampFunc {
4757    pub year: Expression,
4758    pub month: Expression,
4759    pub day: Expression,
4760    pub hour: Expression,
4761    pub minute: Expression,
4762    pub second: Expression,
4763    pub timezone: Option<Expression>,
4764}
4765
4766/// LAST_DAY function with optional date part (for BigQuery granularity like WEEK(SUNDAY))
4767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4768#[cfg_attr(feature = "bindings", derive(TS))]
4769pub struct LastDayFunc {
4770    pub this: Expression,
4771    /// Optional date part for granularity (e.g., MONTH, YEAR, WEEK(SUNDAY))
4772    #[serde(skip_serializing_if = "Option::is_none", default)]
4773    pub unit: Option<DateTimeField>,
4774}
4775
4776// ============================================================================
4777// Array Function types
4778// ============================================================================
4779
4780/// ARRAY constructor
4781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4782#[cfg_attr(feature = "bindings", derive(TS))]
4783pub struct ArrayConstructor {
4784    pub expressions: Vec<Expression>,
4785    pub bracket_notation: bool,
4786    /// True if LIST keyword was used instead of ARRAY (DuckDB)
4787    pub use_list_keyword: bool,
4788}
4789
4790/// ARRAY_SORT function
4791#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4792#[cfg_attr(feature = "bindings", derive(TS))]
4793pub struct ArraySortFunc {
4794    pub this: Expression,
4795    pub comparator: Option<Expression>,
4796    pub desc: bool,
4797    pub nulls_first: Option<bool>,
4798}
4799
4800/// ARRAY_JOIN / ARRAY_TO_STRING function
4801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4802#[cfg_attr(feature = "bindings", derive(TS))]
4803pub struct ArrayJoinFunc {
4804    pub this: Expression,
4805    pub separator: Expression,
4806    pub null_replacement: Option<Expression>,
4807}
4808
4809/// UNNEST function
4810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4811#[cfg_attr(feature = "bindings", derive(TS))]
4812pub struct UnnestFunc {
4813    pub this: Expression,
4814    /// Additional arguments for multi-argument UNNEST (e.g., UNNEST(arr1, arr2))
4815    #[serde(default, skip_serializing_if = "Vec::is_empty")]
4816    pub expressions: Vec<Expression>,
4817    pub with_ordinality: bool,
4818    pub alias: Option<Identifier>,
4819    /// BigQuery: offset alias for WITH OFFSET AS <name>
4820    #[serde(default, skip_serializing_if = "Option::is_none")]
4821    pub offset_alias: Option<Identifier>,
4822}
4823
4824/// ARRAY_FILTER function (with lambda)
4825#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4826#[cfg_attr(feature = "bindings", derive(TS))]
4827pub struct ArrayFilterFunc {
4828    pub this: Expression,
4829    pub filter: Expression,
4830}
4831
4832/// ARRAY_TRANSFORM / TRANSFORM function (with lambda)
4833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4834#[cfg_attr(feature = "bindings", derive(TS))]
4835pub struct ArrayTransformFunc {
4836    pub this: Expression,
4837    pub transform: Expression,
4838}
4839
4840/// SEQUENCE / GENERATE_SERIES function
4841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4842#[cfg_attr(feature = "bindings", derive(TS))]
4843pub struct SequenceFunc {
4844    pub start: Expression,
4845    pub stop: Expression,
4846    pub step: Option<Expression>,
4847}
4848
4849// ============================================================================
4850// Struct Function types
4851// ============================================================================
4852
4853/// STRUCT constructor
4854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4855#[cfg_attr(feature = "bindings", derive(TS))]
4856pub struct StructConstructor {
4857    pub fields: Vec<(Option<Identifier>, Expression)>,
4858}
4859
4860/// STRUCT_EXTRACT function
4861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4862#[cfg_attr(feature = "bindings", derive(TS))]
4863pub struct StructExtractFunc {
4864    pub this: Expression,
4865    pub field: Identifier,
4866}
4867
4868/// NAMED_STRUCT function
4869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4870#[cfg_attr(feature = "bindings", derive(TS))]
4871pub struct NamedStructFunc {
4872    pub pairs: Vec<(Expression, Expression)>,
4873}
4874
4875// ============================================================================
4876// Map Function types
4877// ============================================================================
4878
4879/// MAP constructor
4880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4881#[cfg_attr(feature = "bindings", derive(TS))]
4882pub struct MapConstructor {
4883    pub keys: Vec<Expression>,
4884    pub values: Vec<Expression>,
4885    /// Whether curly brace syntax was used (`{'a': 1}`) vs MAP function (`MAP(...)`)
4886    #[serde(default)]
4887    pub curly_brace_syntax: bool,
4888    /// Whether MAP keyword was present (`MAP {'a': 1}`) vs bare curly braces (`{'a': 1}`)
4889    #[serde(default)]
4890    pub with_map_keyword: bool,
4891}
4892
4893/// TRANSFORM_KEYS / TRANSFORM_VALUES function
4894#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4895#[cfg_attr(feature = "bindings", derive(TS))]
4896pub struct TransformFunc {
4897    pub this: Expression,
4898    pub transform: Expression,
4899}
4900
4901// ============================================================================
4902// JSON Function types
4903// ============================================================================
4904
4905/// JSON_EXTRACT / JSON_EXTRACT_SCALAR function
4906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4907#[cfg_attr(feature = "bindings", derive(TS))]
4908pub struct JsonExtractFunc {
4909    pub this: Expression,
4910    pub path: Expression,
4911    pub returning: Option<DataType>,
4912    /// True if parsed from -> or ->> operator syntax
4913    #[serde(default)]
4914    pub arrow_syntax: bool,
4915    /// True if parsed from #>> operator syntax (PostgreSQL JSONB path text extraction)
4916    #[serde(default)]
4917    pub hash_arrow_syntax: bool,
4918    /// Wrapper option: WITH/WITHOUT [CONDITIONAL|UNCONDITIONAL] [ARRAY] WRAPPER
4919    #[serde(default)]
4920    pub wrapper_option: Option<String>,
4921    /// Quotes handling: KEEP QUOTES or OMIT QUOTES
4922    #[serde(default)]
4923    pub quotes_option: Option<String>,
4924    /// ON SCALAR STRING flag
4925    #[serde(default)]
4926    pub on_scalar_string: bool,
4927    /// Error handling: NULL ON ERROR, ERROR ON ERROR, etc.
4928    #[serde(default)]
4929    pub on_error: Option<String>,
4930}
4931
4932/// JSON path extraction
4933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4934#[cfg_attr(feature = "bindings", derive(TS))]
4935pub struct JsonPathFunc {
4936    pub this: Expression,
4937    pub paths: Vec<Expression>,
4938}
4939
4940/// JSON_OBJECT function
4941#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4942#[cfg_attr(feature = "bindings", derive(TS))]
4943pub struct JsonObjectFunc {
4944    pub pairs: Vec<(Expression, Expression)>,
4945    pub null_handling: Option<JsonNullHandling>,
4946    #[serde(default)]
4947    pub with_unique_keys: bool,
4948    #[serde(default)]
4949    pub returning_type: Option<DataType>,
4950    #[serde(default)]
4951    pub format_json: bool,
4952    #[serde(default)]
4953    pub encoding: Option<String>,
4954    /// For JSON_OBJECT(*) syntax
4955    #[serde(default)]
4956    pub star: bool,
4957}
4958
4959/// JSON null handling options
4960#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4961#[cfg_attr(feature = "bindings", derive(TS))]
4962pub enum JsonNullHandling {
4963    NullOnNull,
4964    AbsentOnNull,
4965}
4966
4967/// JSON_SET / JSON_INSERT function
4968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4969#[cfg_attr(feature = "bindings", derive(TS))]
4970pub struct JsonModifyFunc {
4971    pub this: Expression,
4972    pub path_values: Vec<(Expression, Expression)>,
4973}
4974
4975/// JSON_ARRAYAGG function
4976#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4977#[cfg_attr(feature = "bindings", derive(TS))]
4978pub struct JsonArrayAggFunc {
4979    pub this: Expression,
4980    pub order_by: Option<Vec<Ordered>>,
4981    pub null_handling: Option<JsonNullHandling>,
4982    pub filter: Option<Expression>,
4983}
4984
4985/// JSON_OBJECTAGG function
4986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4987#[cfg_attr(feature = "bindings", derive(TS))]
4988pub struct JsonObjectAggFunc {
4989    pub key: Expression,
4990    pub value: Expression,
4991    pub null_handling: Option<JsonNullHandling>,
4992    pub filter: Option<Expression>,
4993}
4994
4995// ============================================================================
4996// Type Casting Function types
4997// ============================================================================
4998
4999/// CONVERT function (SQL Server style)
5000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5001#[cfg_attr(feature = "bindings", derive(TS))]
5002pub struct ConvertFunc {
5003    pub this: Expression,
5004    pub to: DataType,
5005    pub style: Option<Expression>,
5006}
5007
5008// ============================================================================
5009// Additional Expression types
5010// ============================================================================
5011
5012/// Lambda expression
5013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5014#[cfg_attr(feature = "bindings", derive(TS))]
5015pub struct LambdaExpr {
5016    pub parameters: Vec<Identifier>,
5017    pub body: Expression,
5018    /// True if using DuckDB's LAMBDA x : expr syntax (vs x -> expr)
5019    #[serde(default)]
5020    pub colon: bool,
5021    /// Optional type annotations for parameters (Snowflake: a int -> a + 1)
5022    /// Maps parameter index to data type
5023    #[serde(default)]
5024    pub parameter_types: Vec<Option<DataType>>,
5025}
5026
5027/// Parameter (parameterized queries)
5028#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5029#[cfg_attr(feature = "bindings", derive(TS))]
5030pub struct Parameter {
5031    pub name: Option<String>,
5032    pub index: Option<u32>,
5033    pub style: ParameterStyle,
5034    /// Whether the name was quoted (e.g., @"x" vs @x)
5035    #[serde(default)]
5036    pub quoted: bool,
5037    /// Whether the name was string-quoted with single quotes (e.g., @'foo')
5038    #[serde(default)]
5039    pub string_quoted: bool,
5040    /// Optional secondary expression for ${kind:name} syntax (Hive hiveconf variables)
5041    #[serde(default)]
5042    pub expression: Option<String>,
5043}
5044
5045/// Parameter placeholder styles
5046#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5047#[cfg_attr(feature = "bindings", derive(TS))]
5048pub enum ParameterStyle {
5049    Question,     // ?
5050    Dollar,       // $1, $2
5051    DollarBrace,  // ${name} (Databricks, Hive template variables)
5052    Brace,        // {name} (Spark/Databricks widget/template variables)
5053    Colon,        // :name
5054    At,           // @name
5055    DoubleAt,     // @@name (system variables in MySQL/SQL Server)
5056    DoubleDollar, // $$name
5057    Percent,      // %s, %(name)s (PostgreSQL psycopg2 style)
5058}
5059
5060/// Placeholder expression
5061#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5062#[cfg_attr(feature = "bindings", derive(TS))]
5063pub struct Placeholder {
5064    pub index: Option<u32>,
5065}
5066
5067/// Named argument in function call: name => value or name := value
5068#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5069#[cfg_attr(feature = "bindings", derive(TS))]
5070pub struct NamedArgument {
5071    pub name: Identifier,
5072    pub value: Expression,
5073    /// The separator used: `=>`, `:=`, or `=`
5074    pub separator: NamedArgSeparator,
5075}
5076
5077/// Separator style for named arguments
5078#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5079#[cfg_attr(feature = "bindings", derive(TS))]
5080pub enum NamedArgSeparator {
5081    /// `=>` (standard SQL, Snowflake, BigQuery)
5082    DArrow,
5083    /// `:=` (Oracle, MySQL)
5084    ColonEq,
5085    /// `=` (simple equals, some dialects)
5086    Eq,
5087}
5088
5089/// TABLE ref or MODEL ref used as a function argument (BigQuery)
5090/// e.g., GAP_FILL(TABLE device_data, ...) or ML.PREDICT(MODEL mydataset.mymodel, ...)
5091#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5092#[cfg_attr(feature = "bindings", derive(TS))]
5093pub struct TableArgument {
5094    /// The keyword prefix: "TABLE" or "MODEL"
5095    pub prefix: String,
5096    /// The table/model reference expression
5097    pub this: Expression,
5098}
5099
5100/// SQL Comment preservation
5101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5102#[cfg_attr(feature = "bindings", derive(TS))]
5103pub struct SqlComment {
5104    pub text: String,
5105    pub is_block: bool,
5106}
5107
5108// ============================================================================
5109// Additional Predicate types
5110// ============================================================================
5111
5112/// SIMILAR TO expression
5113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5114#[cfg_attr(feature = "bindings", derive(TS))]
5115pub struct SimilarToExpr {
5116    pub this: Expression,
5117    pub pattern: Expression,
5118    pub escape: Option<Expression>,
5119    pub not: bool,
5120}
5121
5122/// ANY / ALL quantified expression
5123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5124#[cfg_attr(feature = "bindings", derive(TS))]
5125pub struct QuantifiedExpr {
5126    pub this: Expression,
5127    pub subquery: Expression,
5128    pub op: Option<QuantifiedOp>,
5129}
5130
5131/// Comparison operator for quantified expressions
5132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5133#[cfg_attr(feature = "bindings", derive(TS))]
5134pub enum QuantifiedOp {
5135    Eq,
5136    Neq,
5137    Lt,
5138    Lte,
5139    Gt,
5140    Gte,
5141}
5142
5143/// OVERLAPS expression
5144/// Supports two forms:
5145/// 1. Simple binary: a OVERLAPS b (this, expression are set)
5146/// 2. Full ANSI: (a, b) OVERLAPS (c, d) (left_start, left_end, right_start, right_end are set)
5147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5148#[cfg_attr(feature = "bindings", derive(TS))]
5149pub struct OverlapsExpr {
5150    /// Left operand for simple binary form
5151    #[serde(skip_serializing_if = "Option::is_none")]
5152    pub this: Option<Expression>,
5153    /// Right operand for simple binary form
5154    #[serde(skip_serializing_if = "Option::is_none")]
5155    pub expression: Option<Expression>,
5156    /// Left range start for full ANSI form
5157    #[serde(skip_serializing_if = "Option::is_none")]
5158    pub left_start: Option<Expression>,
5159    /// Left range end for full ANSI form
5160    #[serde(skip_serializing_if = "Option::is_none")]
5161    pub left_end: Option<Expression>,
5162    /// Right range start for full ANSI form
5163    #[serde(skip_serializing_if = "Option::is_none")]
5164    pub right_start: Option<Expression>,
5165    /// Right range end for full ANSI form
5166    #[serde(skip_serializing_if = "Option::is_none")]
5167    pub right_end: Option<Expression>,
5168}
5169
5170// ============================================================================
5171// Array/Struct/Map access
5172// ============================================================================
5173
5174/// Subscript access (array[index] or map[key])
5175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5176#[cfg_attr(feature = "bindings", derive(TS))]
5177pub struct Subscript {
5178    pub this: Expression,
5179    pub index: Expression,
5180}
5181
5182/// Dot access (struct.field)
5183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5184#[cfg_attr(feature = "bindings", derive(TS))]
5185pub struct DotAccess {
5186    pub this: Expression,
5187    pub field: Identifier,
5188}
5189
5190/// Method call (expr.method(args))
5191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5192#[cfg_attr(feature = "bindings", derive(TS))]
5193pub struct MethodCall {
5194    pub this: Expression,
5195    pub method: Identifier,
5196    pub args: Vec<Expression>,
5197}
5198
5199/// Array slice (array[start:end])
5200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5201#[cfg_attr(feature = "bindings", derive(TS))]
5202pub struct ArraySlice {
5203    pub this: Expression,
5204    pub start: Option<Expression>,
5205    pub end: Option<Expression>,
5206}
5207
5208// ============================================================================
5209// DDL (Data Definition Language) Statements
5210// ============================================================================
5211
5212/// ON COMMIT behavior for temporary tables
5213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5214#[cfg_attr(feature = "bindings", derive(TS))]
5215pub enum OnCommit {
5216    /// ON COMMIT PRESERVE ROWS
5217    PreserveRows,
5218    /// ON COMMIT DELETE ROWS
5219    DeleteRows,
5220}
5221
5222/// CREATE TABLE statement
5223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5224#[cfg_attr(feature = "bindings", derive(TS))]
5225pub struct CreateTable {
5226    pub name: TableRef,
5227    /// ClickHouse: ON CLUSTER clause for distributed DDL
5228    #[serde(default, skip_serializing_if = "Option::is_none")]
5229    pub on_cluster: Option<OnCluster>,
5230    pub columns: Vec<ColumnDef>,
5231    pub constraints: Vec<TableConstraint>,
5232    pub if_not_exists: bool,
5233    pub temporary: bool,
5234    pub or_replace: bool,
5235    /// Table modifier: DYNAMIC, ICEBERG, EXTERNAL, HYBRID (Snowflake)
5236    #[serde(default, skip_serializing_if = "Option::is_none")]
5237    pub table_modifier: Option<String>,
5238    pub as_select: Option<Expression>,
5239    /// Whether the AS SELECT was wrapped in parentheses
5240    #[serde(default)]
5241    pub as_select_parenthesized: bool,
5242    /// ON COMMIT behavior for temporary tables
5243    #[serde(default)]
5244    pub on_commit: Option<OnCommit>,
5245    /// Clone source table (e.g., CREATE TABLE t CLONE source_table)
5246    #[serde(default)]
5247    pub clone_source: Option<TableRef>,
5248    /// Time travel AT/BEFORE clause for CLONE (e.g., AT(TIMESTAMP => '...'))
5249    #[serde(default, skip_serializing_if = "Option::is_none")]
5250    pub clone_at_clause: Option<Expression>,
5251    /// Whether this is a COPY operation (BigQuery) vs CLONE (Snowflake/Databricks)
5252    #[serde(default)]
5253    pub is_copy: bool,
5254    /// Whether this is a SHALLOW CLONE (Databricks/Delta Lake)
5255    #[serde(default)]
5256    pub shallow_clone: bool,
5257    /// Leading comments before the statement
5258    #[serde(default)]
5259    pub leading_comments: Vec<String>,
5260    /// WITH properties (e.g., WITH (FORMAT='parquet'))
5261    #[serde(default)]
5262    pub with_properties: Vec<(String, String)>,
5263    /// Teradata: table options after name before columns (comma-separated)
5264    #[serde(default)]
5265    pub teradata_post_name_options: Vec<String>,
5266    /// Teradata: WITH DATA (true) or WITH NO DATA (false) after AS SELECT
5267    #[serde(default)]
5268    pub with_data: Option<bool>,
5269    /// Teradata: AND STATISTICS (true) or AND NO STATISTICS (false)
5270    #[serde(default)]
5271    pub with_statistics: Option<bool>,
5272    /// Teradata: Index specifications (NO PRIMARY INDEX, UNIQUE PRIMARY INDEX, etc.)
5273    #[serde(default)]
5274    pub teradata_indexes: Vec<TeradataIndex>,
5275    /// WITH clause (CTEs) - for CREATE TABLE ... AS WITH ... SELECT ...
5276    #[serde(default)]
5277    pub with_cte: Option<With>,
5278    /// Table properties like DEFAULT COLLATE (BigQuery)
5279    #[serde(default)]
5280    pub properties: Vec<Expression>,
5281    /// PostgreSQL PARTITION OF property (e.g., CREATE TABLE t PARTITION OF parent ...)
5282    #[serde(default, skip_serializing_if = "Option::is_none")]
5283    pub partition_of: Option<Expression>,
5284    /// TSQL: WITH(SYSTEM_VERSIONING=ON(...)) after column definitions
5285    #[serde(default)]
5286    pub post_table_properties: Vec<Expression>,
5287    /// MySQL table options after column definitions (ENGINE=val, AUTO_INCREMENT=val, etc.)
5288    #[serde(default)]
5289    pub mysql_table_options: Vec<(String, String)>,
5290    /// PostgreSQL INHERITS clause: INHERITS (parent1, parent2, ...)
5291    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5292    pub inherits: Vec<TableRef>,
5293    /// TSQL ON filegroup or ON filegroup (partition_column) clause
5294    #[serde(default, skip_serializing_if = "Option::is_none")]
5295    pub on_property: Option<OnProperty>,
5296    /// Snowflake: COPY GRANTS clause to copy privileges from replaced table
5297    #[serde(default)]
5298    pub copy_grants: bool,
5299    /// Snowflake: USING TEMPLATE expression for schema inference
5300    #[serde(default, skip_serializing_if = "Option::is_none")]
5301    pub using_template: Option<Box<Expression>>,
5302    /// StarRocks: ROLLUP (r1(col1, col2), r2(col1))
5303    #[serde(default, skip_serializing_if = "Option::is_none")]
5304    pub rollup: Option<RollupProperty>,
5305}
5306
5307/// Teradata index specification for CREATE TABLE
5308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5309#[cfg_attr(feature = "bindings", derive(TS))]
5310pub struct TeradataIndex {
5311    /// Index kind: NoPrimary, Primary, PrimaryAmp, Unique, UniquePrimary
5312    pub kind: TeradataIndexKind,
5313    /// Optional index name
5314    pub name: Option<String>,
5315    /// Optional column list
5316    pub columns: Vec<String>,
5317}
5318
5319/// Kind of Teradata index
5320#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5321#[cfg_attr(feature = "bindings", derive(TS))]
5322pub enum TeradataIndexKind {
5323    /// NO PRIMARY INDEX
5324    NoPrimary,
5325    /// PRIMARY INDEX
5326    Primary,
5327    /// PRIMARY AMP INDEX
5328    PrimaryAmp,
5329    /// UNIQUE INDEX
5330    Unique,
5331    /// UNIQUE PRIMARY INDEX
5332    UniquePrimary,
5333    /// INDEX (secondary, non-primary)
5334    Secondary,
5335}
5336
5337impl CreateTable {
5338    pub fn new(name: impl Into<String>) -> Self {
5339        Self {
5340            name: TableRef::new(name),
5341            on_cluster: None,
5342            columns: Vec::new(),
5343            constraints: Vec::new(),
5344            if_not_exists: false,
5345            temporary: false,
5346            or_replace: false,
5347            table_modifier: None,
5348            as_select: None,
5349            as_select_parenthesized: false,
5350            on_commit: None,
5351            clone_source: None,
5352            clone_at_clause: None,
5353            shallow_clone: false,
5354            is_copy: false,
5355            leading_comments: Vec::new(),
5356            with_properties: Vec::new(),
5357            teradata_post_name_options: Vec::new(),
5358            with_data: None,
5359            with_statistics: None,
5360            teradata_indexes: Vec::new(),
5361            with_cte: None,
5362            properties: Vec::new(),
5363            partition_of: None,
5364            post_table_properties: Vec::new(),
5365            mysql_table_options: Vec::new(),
5366            inherits: Vec::new(),
5367            on_property: None,
5368            copy_grants: false,
5369            using_template: None,
5370            rollup: None,
5371        }
5372    }
5373}
5374
5375/// Sort order for PRIMARY KEY ASC/DESC
5376#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5377#[cfg_attr(feature = "bindings", derive(TS))]
5378pub enum SortOrder {
5379    Asc,
5380    Desc,
5381}
5382
5383/// Type of column constraint for tracking order
5384#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5385#[cfg_attr(feature = "bindings", derive(TS))]
5386pub enum ConstraintType {
5387    NotNull,
5388    Null,
5389    PrimaryKey,
5390    Unique,
5391    Default,
5392    AutoIncrement,
5393    Collate,
5394    Comment,
5395    References,
5396    Check,
5397    GeneratedAsIdentity,
5398    /// Snowflake: TAG (key='value', ...)
5399    Tags,
5400    /// Computed/generated column
5401    ComputedColumn,
5402    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END
5403    GeneratedAsRow,
5404    /// MySQL: ON UPDATE expression
5405    OnUpdate,
5406    /// PATH constraint for XMLTABLE/JSON_TABLE columns
5407    Path,
5408    /// Redshift: ENCODE encoding_type
5409    Encode,
5410}
5411
5412/// Column definition in CREATE TABLE
5413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5414#[cfg_attr(feature = "bindings", derive(TS))]
5415pub struct ColumnDef {
5416    pub name: Identifier,
5417    pub data_type: DataType,
5418    pub nullable: Option<bool>,
5419    pub default: Option<Expression>,
5420    pub primary_key: bool,
5421    /// Sort order for PRIMARY KEY (ASC/DESC)
5422    #[serde(default)]
5423    pub primary_key_order: Option<SortOrder>,
5424    pub unique: bool,
5425    /// PostgreSQL 15+: UNIQUE NULLS NOT DISTINCT
5426    #[serde(default)]
5427    pub unique_nulls_not_distinct: bool,
5428    pub auto_increment: bool,
5429    pub comment: Option<String>,
5430    pub constraints: Vec<ColumnConstraint>,
5431    /// Track original order of constraints for accurate regeneration
5432    #[serde(default)]
5433    pub constraint_order: Vec<ConstraintType>,
5434    /// Teradata: FORMAT 'pattern'
5435    #[serde(default)]
5436    pub format: Option<String>,
5437    /// Teradata: TITLE 'title'
5438    #[serde(default)]
5439    pub title: Option<String>,
5440    /// Teradata: INLINE LENGTH n
5441    #[serde(default)]
5442    pub inline_length: Option<u64>,
5443    /// Teradata: COMPRESS or COMPRESS (values) or COMPRESS 'value'
5444    #[serde(default)]
5445    pub compress: Option<Vec<Expression>>,
5446    /// Teradata: CHARACTER SET name
5447    #[serde(default)]
5448    pub character_set: Option<String>,
5449    /// Teradata: UPPERCASE
5450    #[serde(default)]
5451    pub uppercase: bool,
5452    /// Teradata: CASESPECIFIC / NOT CASESPECIFIC (None = not specified, Some(true) = CASESPECIFIC, Some(false) = NOT CASESPECIFIC)
5453    #[serde(default)]
5454    pub casespecific: Option<bool>,
5455    /// Snowflake: AUTOINCREMENT START value
5456    #[serde(default)]
5457    pub auto_increment_start: Option<Box<Expression>>,
5458    /// Snowflake: AUTOINCREMENT INCREMENT value
5459    #[serde(default)]
5460    pub auto_increment_increment: Option<Box<Expression>>,
5461    /// Snowflake: AUTOINCREMENT ORDER/NOORDER (true = ORDER, false = NOORDER, None = not specified)
5462    #[serde(default)]
5463    pub auto_increment_order: Option<bool>,
5464    /// MySQL: UNSIGNED modifier
5465    #[serde(default)]
5466    pub unsigned: bool,
5467    /// MySQL: ZEROFILL modifier
5468    #[serde(default)]
5469    pub zerofill: bool,
5470    /// MySQL: ON UPDATE expression (e.g., ON UPDATE CURRENT_TIMESTAMP)
5471    #[serde(default, skip_serializing_if = "Option::is_none")]
5472    pub on_update: Option<Expression>,
5473    /// Named constraint for UNIQUE (e.g., CONSTRAINT must_be_different UNIQUE)
5474    #[serde(default, skip_serializing_if = "Option::is_none")]
5475    pub unique_constraint_name: Option<String>,
5476    /// Named constraint for NOT NULL (e.g., CONSTRAINT present NOT NULL)
5477    #[serde(default, skip_serializing_if = "Option::is_none")]
5478    pub not_null_constraint_name: Option<String>,
5479    /// Named constraint for PRIMARY KEY (e.g., CONSTRAINT pk_name PRIMARY KEY)
5480    #[serde(default, skip_serializing_if = "Option::is_none")]
5481    pub primary_key_constraint_name: Option<String>,
5482    /// Named constraint for CHECK (e.g., CONSTRAINT chk_name CHECK(...))
5483    #[serde(default, skip_serializing_if = "Option::is_none")]
5484    pub check_constraint_name: Option<String>,
5485    /// BigQuery: OPTIONS (key=value, ...) on column
5486    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5487    pub options: Vec<Expression>,
5488    /// SQLite: Column definition without explicit type
5489    #[serde(default)]
5490    pub no_type: bool,
5491    /// Redshift: ENCODE encoding_type (e.g., ZSTD, DELTA, LZO, etc.)
5492    #[serde(default, skip_serializing_if = "Option::is_none")]
5493    pub encoding: Option<String>,
5494    /// ClickHouse: CODEC(LZ4HC(9), ZSTD, DELTA)
5495    #[serde(default, skip_serializing_if = "Option::is_none")]
5496    pub codec: Option<String>,
5497    /// ClickHouse: EPHEMERAL [expr] modifier
5498    #[serde(default, skip_serializing_if = "Option::is_none")]
5499    pub ephemeral: Option<Option<Box<Expression>>>,
5500    /// ClickHouse: MATERIALIZED expr modifier
5501    #[serde(default, skip_serializing_if = "Option::is_none")]
5502    pub materialized_expr: Option<Box<Expression>>,
5503    /// ClickHouse: ALIAS expr modifier
5504    #[serde(default, skip_serializing_if = "Option::is_none")]
5505    pub alias_expr: Option<Box<Expression>>,
5506    /// ClickHouse: TTL expr modifier on columns
5507    #[serde(default, skip_serializing_if = "Option::is_none")]
5508    pub ttl_expr: Option<Box<Expression>>,
5509    /// TSQL: NOT FOR REPLICATION
5510    #[serde(default)]
5511    pub not_for_replication: bool,
5512}
5513
5514impl ColumnDef {
5515    pub fn new(name: impl Into<String>, data_type: DataType) -> Self {
5516        Self {
5517            name: Identifier::new(name),
5518            data_type,
5519            nullable: None,
5520            default: None,
5521            primary_key: false,
5522            primary_key_order: None,
5523            unique: false,
5524            unique_nulls_not_distinct: false,
5525            auto_increment: false,
5526            comment: None,
5527            constraints: Vec::new(),
5528            constraint_order: Vec::new(),
5529            format: None,
5530            title: None,
5531            inline_length: None,
5532            compress: None,
5533            character_set: None,
5534            uppercase: false,
5535            casespecific: None,
5536            auto_increment_start: None,
5537            auto_increment_increment: None,
5538            auto_increment_order: None,
5539            unsigned: false,
5540            zerofill: false,
5541            on_update: None,
5542            unique_constraint_name: None,
5543            not_null_constraint_name: None,
5544            primary_key_constraint_name: None,
5545            check_constraint_name: None,
5546            options: Vec::new(),
5547            no_type: false,
5548            encoding: None,
5549            codec: None,
5550            ephemeral: None,
5551            materialized_expr: None,
5552            alias_expr: None,
5553            ttl_expr: None,
5554            not_for_replication: false,
5555        }
5556    }
5557}
5558
5559/// Column-level constraint
5560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5561#[cfg_attr(feature = "bindings", derive(TS))]
5562pub enum ColumnConstraint {
5563    NotNull,
5564    Null,
5565    Unique,
5566    PrimaryKey,
5567    Default(Expression),
5568    Check(Expression),
5569    References(ForeignKeyRef),
5570    GeneratedAsIdentity(GeneratedAsIdentity),
5571    Collate(Identifier),
5572    Comment(String),
5573    /// Snowflake: TAG (key='value', ...)
5574    Tags(Tags),
5575    /// Computed/generated column: GENERATED ALWAYS AS (expr) STORED|VIRTUAL (MySQL/PostgreSQL)
5576    /// or AS (expr) PERSISTED [NOT NULL] (TSQL)
5577    ComputedColumn(ComputedColumn),
5578    /// TSQL temporal: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5579    GeneratedAsRow(GeneratedAsRow),
5580    /// PATH constraint for XMLTABLE/JSON_TABLE columns: PATH 'xpath'
5581    Path(Expression),
5582}
5583
5584/// Computed/generated column constraint
5585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5586#[cfg_attr(feature = "bindings", derive(TS))]
5587pub struct ComputedColumn {
5588    /// The expression that computes the column value
5589    pub expression: Box<Expression>,
5590    /// PERSISTED (TSQL) or STORED (MySQL/PostgreSQL) = true; VIRTUAL = false; None = not specified
5591    #[serde(default)]
5592    pub persisted: bool,
5593    /// NOT NULL (TSQL computed columns)
5594    #[serde(default)]
5595    pub not_null: bool,
5596    /// The persistence keyword used: "STORED", "VIRTUAL", or "PERSISTED"
5597    /// When None, defaults to dialect-appropriate output
5598    #[serde(default)]
5599    pub persistence_kind: Option<String>,
5600    /// Optional data type for SingleStore: AS (expr) PERSISTED TYPE NOT NULL
5601    #[serde(default, skip_serializing_if = "Option::is_none")]
5602    pub data_type: Option<DataType>,
5603}
5604
5605/// TSQL temporal column constraint: GENERATED ALWAYS AS ROW START|END [HIDDEN]
5606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5607#[cfg_attr(feature = "bindings", derive(TS))]
5608pub struct GeneratedAsRow {
5609    /// true = ROW START, false = ROW END
5610    pub start: bool,
5611    /// HIDDEN modifier
5612    #[serde(default)]
5613    pub hidden: bool,
5614}
5615
5616/// Generated identity column constraint
5617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5618#[cfg_attr(feature = "bindings", derive(TS))]
5619pub struct GeneratedAsIdentity {
5620    /// True for ALWAYS, False for BY DEFAULT
5621    pub always: bool,
5622    /// ON NULL (only valid with BY DEFAULT)
5623    pub on_null: bool,
5624    /// START WITH value
5625    pub start: Option<Box<Expression>>,
5626    /// INCREMENT BY value
5627    pub increment: Option<Box<Expression>>,
5628    /// MINVALUE
5629    pub minvalue: Option<Box<Expression>>,
5630    /// MAXVALUE
5631    pub maxvalue: Option<Box<Expression>>,
5632    /// CYCLE option - Some(true) = CYCLE, Some(false) = NO CYCLE, None = not specified
5633    pub cycle: Option<bool>,
5634}
5635
5636/// Constraint modifiers (shared between table-level constraints)
5637#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
5638#[cfg_attr(feature = "bindings", derive(TS))]
5639pub struct ConstraintModifiers {
5640    /// ENFORCED / NOT ENFORCED
5641    pub enforced: Option<bool>,
5642    /// DEFERRABLE / NOT DEFERRABLE
5643    pub deferrable: Option<bool>,
5644    /// INITIALLY DEFERRED / INITIALLY IMMEDIATE
5645    pub initially_deferred: Option<bool>,
5646    /// NORELY (Oracle)
5647    pub norely: bool,
5648    /// RELY (Oracle)
5649    pub rely: bool,
5650    /// USING index type (MySQL): BTREE or HASH
5651    #[serde(default)]
5652    pub using: Option<String>,
5653    /// True if USING appeared before columns (MySQL: INDEX USING BTREE (col) vs INDEX (col) USING BTREE)
5654    #[serde(default)]
5655    pub using_before_columns: bool,
5656    /// MySQL index COMMENT 'text'
5657    #[serde(default, skip_serializing_if = "Option::is_none")]
5658    pub comment: Option<String>,
5659    /// MySQL index VISIBLE/INVISIBLE
5660    #[serde(default, skip_serializing_if = "Option::is_none")]
5661    pub visible: Option<bool>,
5662    /// MySQL ENGINE_ATTRIBUTE = 'value'
5663    #[serde(default, skip_serializing_if = "Option::is_none")]
5664    pub engine_attribute: Option<String>,
5665    /// MySQL WITH PARSER name
5666    #[serde(default, skip_serializing_if = "Option::is_none")]
5667    pub with_parser: Option<String>,
5668    /// PostgreSQL NOT VALID (constraint is not validated against existing data)
5669    #[serde(default)]
5670    pub not_valid: bool,
5671    /// TSQL CLUSTERED/NONCLUSTERED modifier
5672    #[serde(default, skip_serializing_if = "Option::is_none")]
5673    pub clustered: Option<String>,
5674    /// SQLite ON CONFLICT clause: ROLLBACK, ABORT, FAIL, IGNORE, or REPLACE
5675    #[serde(default, skip_serializing_if = "Option::is_none")]
5676    pub on_conflict: Option<String>,
5677    /// TSQL WITH options (e.g., PAD_INDEX=ON, STATISTICS_NORECOMPUTE=OFF)
5678    #[serde(default, skip_serializing_if = "Vec::is_empty")]
5679    pub with_options: Vec<(String, String)>,
5680    /// TSQL ON filegroup (e.g., ON [INDEX], ON [PRIMARY])
5681    #[serde(default, skip_serializing_if = "Option::is_none")]
5682    pub on_filegroup: Option<Identifier>,
5683}
5684
5685/// Table-level constraint
5686#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5687#[cfg_attr(feature = "bindings", derive(TS))]
5688pub enum TableConstraint {
5689    PrimaryKey {
5690        name: Option<Identifier>,
5691        columns: Vec<Identifier>,
5692        /// INCLUDE (columns) - non-key columns included in the index (PostgreSQL)
5693        #[serde(default)]
5694        include_columns: Vec<Identifier>,
5695        #[serde(default)]
5696        modifiers: ConstraintModifiers,
5697        /// Whether the CONSTRAINT keyword was used (vs MySQL's `PRIMARY KEY name (cols)` syntax)
5698        #[serde(default)]
5699        has_constraint_keyword: bool,
5700    },
5701    Unique {
5702        name: Option<Identifier>,
5703        columns: Vec<Identifier>,
5704        /// Whether columns are parenthesized (false for UNIQUE idx_name without parens)
5705        #[serde(default)]
5706        columns_parenthesized: bool,
5707        #[serde(default)]
5708        modifiers: ConstraintModifiers,
5709        /// Whether the CONSTRAINT keyword was used (vs MySQL's `UNIQUE name (cols)` syntax)
5710        #[serde(default)]
5711        has_constraint_keyword: bool,
5712        /// PostgreSQL 15+: NULLS NOT DISTINCT
5713        #[serde(default)]
5714        nulls_not_distinct: bool,
5715    },
5716    ForeignKey {
5717        name: Option<Identifier>,
5718        columns: Vec<Identifier>,
5719        #[serde(default)]
5720        references: Option<ForeignKeyRef>,
5721        /// ON DELETE action when REFERENCES is absent
5722        #[serde(default)]
5723        on_delete: Option<ReferentialAction>,
5724        /// ON UPDATE action when REFERENCES is absent
5725        #[serde(default)]
5726        on_update: Option<ReferentialAction>,
5727        #[serde(default)]
5728        modifiers: ConstraintModifiers,
5729    },
5730    Check {
5731        name: Option<Identifier>,
5732        expression: Expression,
5733        #[serde(default)]
5734        modifiers: ConstraintModifiers,
5735    },
5736    /// INDEX / KEY constraint (MySQL)
5737    Index {
5738        name: Option<Identifier>,
5739        columns: Vec<Identifier>,
5740        /// Index kind: UNIQUE, FULLTEXT, SPATIAL, etc.
5741        #[serde(default)]
5742        kind: Option<String>,
5743        #[serde(default)]
5744        modifiers: ConstraintModifiers,
5745        /// True if KEY keyword was used instead of INDEX
5746        #[serde(default)]
5747        use_key_keyword: bool,
5748        /// ClickHouse: indexed expression (instead of columns)
5749        #[serde(default, skip_serializing_if = "Option::is_none")]
5750        expression: Option<Box<Expression>>,
5751        /// ClickHouse: TYPE type_func(args)
5752        #[serde(default, skip_serializing_if = "Option::is_none")]
5753        index_type: Option<Box<Expression>>,
5754        /// ClickHouse: GRANULARITY n
5755        #[serde(default, skip_serializing_if = "Option::is_none")]
5756        granularity: Option<Box<Expression>>,
5757    },
5758    /// ClickHouse PROJECTION definition
5759    Projection {
5760        name: Identifier,
5761        expression: Expression,
5762    },
5763    /// PostgreSQL LIKE clause: LIKE source_table [INCLUDING|EXCLUDING options]
5764    Like {
5765        source: TableRef,
5766        /// Options as (INCLUDING|EXCLUDING, property) pairs
5767        options: Vec<(LikeOptionAction, String)>,
5768    },
5769    /// TSQL PERIOD FOR SYSTEM_TIME (start_col, end_col)
5770    PeriodForSystemTime {
5771        start_col: Identifier,
5772        end_col: Identifier,
5773    },
5774    /// PostgreSQL EXCLUDE constraint
5775    /// EXCLUDE [USING method] (element WITH operator, ...) [INCLUDE (cols)] [WHERE (expr)] [WITH (params)]
5776    Exclude {
5777        name: Option<Identifier>,
5778        /// Index access method (gist, btree, etc.)
5779        #[serde(default)]
5780        using: Option<String>,
5781        /// Elements: (expression, operator) pairs
5782        elements: Vec<ExcludeElement>,
5783        /// INCLUDE columns
5784        #[serde(default)]
5785        include_columns: Vec<Identifier>,
5786        /// WHERE predicate
5787        #[serde(default)]
5788        where_clause: Option<Box<Expression>>,
5789        /// WITH (storage_parameters)
5790        #[serde(default)]
5791        with_params: Vec<(String, String)>,
5792        /// USING INDEX TABLESPACE tablespace_name
5793        #[serde(default)]
5794        using_index_tablespace: Option<String>,
5795        #[serde(default)]
5796        modifiers: ConstraintModifiers,
5797    },
5798    /// Snowflake TAG clause: TAG (key='value', key2='value2')
5799    Tags(Tags),
5800    /// PostgreSQL table-level INITIALLY DEFERRED/INITIALLY IMMEDIATE
5801    /// This is a standalone clause at the end of the CREATE TABLE that sets the default
5802    /// for all deferrable constraints in the table
5803    InitiallyDeferred {
5804        /// true = INITIALLY DEFERRED, false = INITIALLY IMMEDIATE
5805        deferred: bool,
5806    },
5807}
5808
5809/// Element in an EXCLUDE constraint: expression WITH operator
5810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5811#[cfg_attr(feature = "bindings", derive(TS))]
5812pub struct ExcludeElement {
5813    /// The column expression (may include operator class, ordering, nulls)
5814    pub expression: String,
5815    /// The operator (e.g., &&, =)
5816    pub operator: String,
5817}
5818
5819/// Action for LIKE clause options
5820#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5821#[cfg_attr(feature = "bindings", derive(TS))]
5822pub enum LikeOptionAction {
5823    Including,
5824    Excluding,
5825}
5826
5827/// MATCH type for foreign keys
5828#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5829#[cfg_attr(feature = "bindings", derive(TS))]
5830pub enum MatchType {
5831    Full,
5832    Partial,
5833    Simple,
5834}
5835
5836/// Foreign key reference
5837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5838#[cfg_attr(feature = "bindings", derive(TS))]
5839pub struct ForeignKeyRef {
5840    pub table: TableRef,
5841    pub columns: Vec<Identifier>,
5842    pub on_delete: Option<ReferentialAction>,
5843    pub on_update: Option<ReferentialAction>,
5844    /// True if ON UPDATE appears before ON DELETE in the original SQL
5845    #[serde(default)]
5846    pub on_update_first: bool,
5847    /// MATCH clause (FULL, PARTIAL, SIMPLE)
5848    #[serde(default)]
5849    pub match_type: Option<MatchType>,
5850    /// True if MATCH appears after ON DELETE/ON UPDATE clauses
5851    #[serde(default)]
5852    pub match_after_actions: bool,
5853    /// CONSTRAINT name (e.g., CONSTRAINT fk_name REFERENCES ...)
5854    #[serde(default)]
5855    pub constraint_name: Option<String>,
5856    /// DEFERRABLE / NOT DEFERRABLE
5857    #[serde(default)]
5858    pub deferrable: Option<bool>,
5859    /// Snowflake: FOREIGN KEY REFERENCES (includes FOREIGN KEY keywords before REFERENCES)
5860    #[serde(default)]
5861    pub has_foreign_key_keywords: bool,
5862}
5863
5864/// Referential action for foreign keys
5865#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5866#[cfg_attr(feature = "bindings", derive(TS))]
5867pub enum ReferentialAction {
5868    Cascade,
5869    SetNull,
5870    SetDefault,
5871    Restrict,
5872    NoAction,
5873}
5874
5875/// DROP TABLE statement
5876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5877#[cfg_attr(feature = "bindings", derive(TS))]
5878pub struct DropTable {
5879    pub names: Vec<TableRef>,
5880    pub if_exists: bool,
5881    pub cascade: bool,
5882    /// Oracle: CASCADE CONSTRAINTS
5883    #[serde(default)]
5884    pub cascade_constraints: bool,
5885    /// Oracle: PURGE
5886    #[serde(default)]
5887    pub purge: bool,
5888    /// Comments that appear before the DROP keyword (e.g., leading line comments)
5889    #[serde(default)]
5890    pub leading_comments: Vec<String>,
5891}
5892
5893impl DropTable {
5894    pub fn new(name: impl Into<String>) -> Self {
5895        Self {
5896            names: vec![TableRef::new(name)],
5897            if_exists: false,
5898            cascade: false,
5899            cascade_constraints: false,
5900            purge: false,
5901            leading_comments: Vec::new(),
5902        }
5903    }
5904}
5905
5906/// ALTER TABLE statement
5907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5908#[cfg_attr(feature = "bindings", derive(TS))]
5909pub struct AlterTable {
5910    pub name: TableRef,
5911    pub actions: Vec<AlterTableAction>,
5912    /// IF EXISTS clause
5913    #[serde(default)]
5914    pub if_exists: bool,
5915    /// MySQL: ALGORITHM=INPLACE|COPY|DEFAULT|INSTANT
5916    #[serde(default, skip_serializing_if = "Option::is_none")]
5917    pub algorithm: Option<String>,
5918    /// MySQL: LOCK=NONE|SHARED|DEFAULT|EXCLUSIVE
5919    #[serde(default, skip_serializing_if = "Option::is_none")]
5920    pub lock: Option<String>,
5921    /// TSQL: WITH CHECK / WITH NOCHECK modifier before ADD CONSTRAINT
5922    #[serde(default, skip_serializing_if = "Option::is_none")]
5923    pub with_check: Option<String>,
5924    /// Hive: PARTITION clause before actions (e.g., ALTER TABLE x PARTITION(y=z) ADD COLUMN ...)
5925    #[serde(default, skip_serializing_if = "Option::is_none")]
5926    pub partition: Option<Vec<(Identifier, Expression)>>,
5927    /// ClickHouse: ON CLUSTER clause for distributed DDL
5928    #[serde(default, skip_serializing_if = "Option::is_none")]
5929    pub on_cluster: Option<OnCluster>,
5930}
5931
5932impl AlterTable {
5933    pub fn new(name: impl Into<String>) -> Self {
5934        Self {
5935            name: TableRef::new(name),
5936            actions: Vec::new(),
5937            if_exists: false,
5938            algorithm: None,
5939            lock: None,
5940            with_check: None,
5941            partition: None,
5942            on_cluster: None,
5943        }
5944    }
5945}
5946
5947/// Column position for ADD COLUMN (MySQL/MariaDB)
5948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5949#[cfg_attr(feature = "bindings", derive(TS))]
5950pub enum ColumnPosition {
5951    First,
5952    After(Identifier),
5953}
5954
5955/// Actions for ALTER TABLE
5956#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5957#[cfg_attr(feature = "bindings", derive(TS))]
5958pub enum AlterTableAction {
5959    AddColumn {
5960        column: ColumnDef,
5961        if_not_exists: bool,
5962        position: Option<ColumnPosition>,
5963    },
5964    DropColumn {
5965        name: Identifier,
5966        if_exists: bool,
5967        cascade: bool,
5968    },
5969    RenameColumn {
5970        old_name: Identifier,
5971        new_name: Identifier,
5972        if_exists: bool,
5973    },
5974    AlterColumn {
5975        name: Identifier,
5976        action: AlterColumnAction,
5977        /// Whether this was parsed from MODIFY COLUMN syntax (MySQL)
5978        #[serde(default)]
5979        use_modify_keyword: bool,
5980    },
5981    RenameTable(TableRef),
5982    AddConstraint(TableConstraint),
5983    DropConstraint {
5984        name: Identifier,
5985        if_exists: bool,
5986    },
5987    /// DROP FOREIGN KEY action (Oracle/MySQL): ALTER TABLE t DROP FOREIGN KEY fk_name
5988    DropForeignKey {
5989        name: Identifier,
5990    },
5991    /// DROP PARTITION action (Hive/BigQuery)
5992    DropPartition {
5993        /// List of partitions to drop (each partition is a list of key=value pairs)
5994        partitions: Vec<Vec<(Identifier, Expression)>>,
5995        if_exists: bool,
5996    },
5997    /// ADD PARTITION action (Hive/Spark)
5998    AddPartition {
5999        /// The partition expression
6000        partition: Expression,
6001        if_not_exists: bool,
6002        location: Option<Expression>,
6003    },
6004    /// DELETE action (BigQuery): ALTER TABLE t DELETE WHERE condition
6005    Delete {
6006        where_clause: Expression,
6007    },
6008    /// SWAP WITH action (Snowflake): ALTER TABLE a SWAP WITH b
6009    SwapWith(TableRef),
6010    /// SET property action (Snowflake): ALTER TABLE t SET property=value
6011    SetProperty {
6012        properties: Vec<(String, Expression)>,
6013    },
6014    /// UNSET property action (Snowflake): ALTER TABLE t UNSET property
6015    UnsetProperty {
6016        properties: Vec<String>,
6017    },
6018    /// CLUSTER BY action (Snowflake): ALTER TABLE t CLUSTER BY (col1, col2)
6019    ClusterBy {
6020        expressions: Vec<Expression>,
6021    },
6022    /// SET TAG action (Snowflake): ALTER TABLE t SET TAG key='value'
6023    SetTag {
6024        expressions: Vec<(String, Expression)>,
6025    },
6026    /// UNSET TAG action (Snowflake): ALTER TABLE t UNSET TAG key1, key2
6027    UnsetTag {
6028        names: Vec<String>,
6029    },
6030    /// SET with parenthesized options (TSQL): ALTER TABLE t SET (SYSTEM_VERSIONING=ON, ...)
6031    SetOptions {
6032        expressions: Vec<Expression>,
6033    },
6034    /// ALTER INDEX action (MySQL): ALTER TABLE t ALTER INDEX i VISIBLE/INVISIBLE
6035    AlterIndex {
6036        name: Identifier,
6037        visible: bool,
6038    },
6039    /// PostgreSQL: ALTER TABLE t SET LOGGED/UNLOGGED/WITHOUT CLUSTER/WITHOUT OIDS/ACCESS METHOD/TABLESPACE
6040    SetAttribute {
6041        attribute: String,
6042    },
6043    /// Snowflake: ALTER TABLE t SET STAGE_FILE_FORMAT = (options)
6044    SetStageFileFormat {
6045        options: Option<Expression>,
6046    },
6047    /// Snowflake: ALTER TABLE t SET STAGE_COPY_OPTIONS = (options)
6048    SetStageCopyOptions {
6049        options: Option<Expression>,
6050    },
6051    /// Hive/Spark: ADD COLUMNS (col1 TYPE, col2 TYPE) [CASCADE]
6052    AddColumns {
6053        columns: Vec<ColumnDef>,
6054        cascade: bool,
6055    },
6056    /// Spark/Databricks: DROP COLUMNS (col1, col2, ...)
6057    DropColumns {
6058        names: Vec<Identifier>,
6059    },
6060    /// Hive/MySQL/SingleStore: CHANGE [COLUMN] old_name new_name [data_type] [COMMENT 'comment']
6061    /// In SingleStore, data_type can be omitted for simple column renames
6062    ChangeColumn {
6063        old_name: Identifier,
6064        new_name: Identifier,
6065        #[serde(default, skip_serializing_if = "Option::is_none")]
6066        data_type: Option<DataType>,
6067        comment: Option<String>,
6068        #[serde(default)]
6069        cascade: bool,
6070    },
6071    /// Redshift: ALTER TABLE t ALTER SORTKEY AUTO|NONE|(col1, col2)
6072    /// Also: ALTER TABLE t ALTER COMPOUND SORTKEY (col1, col2)
6073    AlterSortKey {
6074        /// AUTO or NONE keyword
6075        this: Option<String>,
6076        /// Column list for (col1, col2) syntax
6077        expressions: Vec<Expression>,
6078        /// Whether COMPOUND keyword was present
6079        compound: bool,
6080    },
6081    /// Redshift: ALTER TABLE t ALTER DISTSTYLE ALL|EVEN|AUTO|KEY
6082    /// Also: ALTER TABLE t ALTER DISTSTYLE KEY DISTKEY col
6083    /// Also: ALTER TABLE t ALTER DISTKEY col (shorthand for DISTSTYLE KEY DISTKEY col)
6084    AlterDistStyle {
6085        /// Distribution style: ALL, EVEN, AUTO, or KEY
6086        style: String,
6087        /// DISTKEY column (only when style is KEY)
6088        distkey: Option<Identifier>,
6089    },
6090    /// Redshift: ALTER TABLE t SET TABLE PROPERTIES ('a' = '5', 'b' = 'c')
6091    SetTableProperties {
6092        properties: Vec<(Expression, Expression)>,
6093    },
6094    /// Redshift: ALTER TABLE t SET LOCATION 's3://bucket/folder/'
6095    SetLocation {
6096        location: String,
6097    },
6098    /// Redshift: ALTER TABLE t SET FILE FORMAT AVRO
6099    SetFileFormat {
6100        format: String,
6101    },
6102    /// ClickHouse: ALTER TABLE t REPLACE PARTITION expr FROM source_table
6103    ReplacePartition {
6104        partition: Expression,
6105        source: Option<Box<Expression>>,
6106    },
6107    /// Raw SQL for dialect-specific ALTER TABLE actions (e.g., ClickHouse UPDATE/DELETE/DETACH/etc.)
6108    Raw {
6109        sql: String,
6110    },
6111}
6112
6113/// Actions for ALTER COLUMN
6114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6115#[cfg_attr(feature = "bindings", derive(TS))]
6116pub enum AlterColumnAction {
6117    SetDataType {
6118        data_type: DataType,
6119        /// USING expression for type conversion (PostgreSQL)
6120        using: Option<Expression>,
6121        /// COLLATE clause (TSQL: ALTER COLUMN col TYPE COLLATE collation_name)
6122        #[serde(default, skip_serializing_if = "Option::is_none")]
6123        collate: Option<String>,
6124    },
6125    SetDefault(Expression),
6126    DropDefault,
6127    SetNotNull,
6128    DropNotNull,
6129    /// Set column comment
6130    Comment(String),
6131    /// MySQL: SET VISIBLE
6132    SetVisible,
6133    /// MySQL: SET INVISIBLE
6134    SetInvisible,
6135}
6136
6137/// CREATE INDEX statement
6138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6139#[cfg_attr(feature = "bindings", derive(TS))]
6140pub struct CreateIndex {
6141    pub name: Identifier,
6142    pub table: TableRef,
6143    pub columns: Vec<IndexColumn>,
6144    pub unique: bool,
6145    pub if_not_exists: bool,
6146    pub using: Option<String>,
6147    /// TSQL CLUSTERED/NONCLUSTERED modifier
6148    #[serde(default)]
6149    pub clustered: Option<String>,
6150    /// PostgreSQL CONCURRENTLY modifier
6151    #[serde(default)]
6152    pub concurrently: bool,
6153    /// PostgreSQL WHERE clause for partial indexes
6154    #[serde(default)]
6155    pub where_clause: Option<Box<Expression>>,
6156    /// PostgreSQL INCLUDE columns
6157    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6158    pub include_columns: Vec<Identifier>,
6159    /// TSQL WITH options (e.g., allow_page_locks=on)
6160    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6161    pub with_options: Vec<(String, String)>,
6162    /// TSQL ON filegroup or partition scheme (e.g., ON PRIMARY, ON X([y]))
6163    #[serde(default)]
6164    pub on_filegroup: Option<String>,
6165}
6166
6167impl CreateIndex {
6168    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
6169        Self {
6170            name: Identifier::new(name),
6171            table: TableRef::new(table),
6172            columns: Vec::new(),
6173            unique: false,
6174            if_not_exists: false,
6175            using: None,
6176            clustered: None,
6177            concurrently: false,
6178            where_clause: None,
6179            include_columns: Vec::new(),
6180            with_options: Vec::new(),
6181            on_filegroup: None,
6182        }
6183    }
6184}
6185
6186/// Index column specification
6187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6188#[cfg_attr(feature = "bindings", derive(TS))]
6189pub struct IndexColumn {
6190    pub column: Identifier,
6191    pub desc: bool,
6192    /// Explicit ASC keyword was present
6193    #[serde(default)]
6194    pub asc: bool,
6195    pub nulls_first: Option<bool>,
6196    /// PostgreSQL operator class (e.g., varchar_pattern_ops, public.gin_trgm_ops)
6197    #[serde(default, skip_serializing_if = "Option::is_none")]
6198    pub opclass: Option<String>,
6199}
6200
6201/// DROP INDEX statement
6202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6203#[cfg_attr(feature = "bindings", derive(TS))]
6204pub struct DropIndex {
6205    pub name: Identifier,
6206    pub table: Option<TableRef>,
6207    pub if_exists: bool,
6208    /// PostgreSQL CONCURRENTLY modifier
6209    #[serde(default)]
6210    pub concurrently: bool,
6211}
6212
6213impl DropIndex {
6214    pub fn new(name: impl Into<String>) -> Self {
6215        Self {
6216            name: Identifier::new(name),
6217            table: None,
6218            if_exists: false,
6219            concurrently: false,
6220        }
6221    }
6222}
6223
6224/// View column definition with optional COMMENT and OPTIONS (BigQuery)
6225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6226#[cfg_attr(feature = "bindings", derive(TS))]
6227pub struct ViewColumn {
6228    pub name: Identifier,
6229    pub comment: Option<String>,
6230    /// BigQuery: OPTIONS (key=value, ...) on column
6231    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6232    pub options: Vec<Expression>,
6233}
6234
6235impl ViewColumn {
6236    pub fn new(name: impl Into<String>) -> Self {
6237        Self {
6238            name: Identifier::new(name),
6239            comment: None,
6240            options: Vec::new(),
6241        }
6242    }
6243
6244    pub fn with_comment(name: impl Into<String>, comment: impl Into<String>) -> Self {
6245        Self {
6246            name: Identifier::new(name),
6247            comment: Some(comment.into()),
6248            options: Vec::new(),
6249        }
6250    }
6251}
6252
6253/// CREATE VIEW statement
6254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6255#[cfg_attr(feature = "bindings", derive(TS))]
6256pub struct CreateView {
6257    pub name: TableRef,
6258    pub columns: Vec<ViewColumn>,
6259    pub query: Expression,
6260    pub or_replace: bool,
6261    pub if_not_exists: bool,
6262    pub materialized: bool,
6263    pub temporary: bool,
6264    /// Snowflake: SECURE VIEW
6265    #[serde(default)]
6266    pub secure: bool,
6267    /// MySQL: ALGORITHM=UNDEFINED/MERGE/TEMPTABLE
6268    #[serde(skip_serializing_if = "Option::is_none")]
6269    pub algorithm: Option<String>,
6270    /// MySQL: DEFINER=user@host
6271    #[serde(skip_serializing_if = "Option::is_none")]
6272    pub definer: Option<String>,
6273    /// MySQL: SQL SECURITY DEFINER/INVOKER; Presto: SECURITY DEFINER/INVOKER
6274    #[serde(skip_serializing_if = "Option::is_none")]
6275    pub security: Option<FunctionSecurity>,
6276    /// True for MySQL-style "SQL SECURITY", false for Presto-style "SECURITY"
6277    #[serde(default = "default_true")]
6278    pub security_sql_style: bool,
6279    /// Whether the query was parenthesized: AS (SELECT ...)
6280    #[serde(default)]
6281    pub query_parenthesized: bool,
6282    /// Teradata: LOCKING mode (ROW, TABLE, DATABASE)
6283    #[serde(skip_serializing_if = "Option::is_none")]
6284    pub locking_mode: Option<String>,
6285    /// Teradata: LOCKING access type (ACCESS, READ, WRITE)
6286    #[serde(skip_serializing_if = "Option::is_none")]
6287    pub locking_access: Option<String>,
6288    /// Snowflake: COPY GRANTS
6289    #[serde(default)]
6290    pub copy_grants: bool,
6291    /// Snowflake: COMMENT = 'text'
6292    #[serde(skip_serializing_if = "Option::is_none", default)]
6293    pub comment: Option<String>,
6294    /// Snowflake: TAG (name='value', ...)
6295    #[serde(default)]
6296    pub tags: Vec<(String, String)>,
6297    /// BigQuery: OPTIONS (key=value, ...)
6298    #[serde(default)]
6299    pub options: Vec<Expression>,
6300    /// Doris: BUILD IMMEDIATE/DEFERRED for materialized views
6301    #[serde(skip_serializing_if = "Option::is_none", default)]
6302    pub build: Option<String>,
6303    /// Doris: REFRESH property for materialized views
6304    #[serde(skip_serializing_if = "Option::is_none", default)]
6305    pub refresh: Option<Box<RefreshTriggerProperty>>,
6306    /// Doris: Schema with typed column definitions for materialized views
6307    /// This is used instead of `columns` when the view has typed column definitions
6308    #[serde(skip_serializing_if = "Option::is_none", default)]
6309    pub schema: Option<Box<Schema>>,
6310    /// Doris: KEY (columns) for materialized views
6311    #[serde(skip_serializing_if = "Option::is_none", default)]
6312    pub unique_key: Option<Box<UniqueKeyProperty>>,
6313    /// Redshift: WITH NO SCHEMA BINDING
6314    #[serde(default)]
6315    pub no_schema_binding: bool,
6316    /// Redshift: AUTO REFRESH YES|NO for materialized views
6317    #[serde(skip_serializing_if = "Option::is_none", default)]
6318    pub auto_refresh: Option<bool>,
6319    /// ClickHouse: ON CLUSTER clause
6320    #[serde(default, skip_serializing_if = "Option::is_none")]
6321    pub on_cluster: Option<OnCluster>,
6322    /// ClickHouse: TO destination_table
6323    #[serde(default, skip_serializing_if = "Option::is_none")]
6324    pub to_table: Option<TableRef>,
6325    /// ClickHouse: Table properties (ENGINE, ORDER BY, SAMPLE, SETTINGS, TTL, etc.) for materialized views
6326    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6327    pub table_properties: Vec<Expression>,
6328}
6329
6330impl CreateView {
6331    pub fn new(name: impl Into<String>, query: Expression) -> Self {
6332        Self {
6333            name: TableRef::new(name),
6334            columns: Vec::new(),
6335            query,
6336            or_replace: false,
6337            if_not_exists: false,
6338            materialized: false,
6339            temporary: false,
6340            secure: false,
6341            algorithm: None,
6342            definer: None,
6343            security: None,
6344            security_sql_style: true,
6345            query_parenthesized: false,
6346            locking_mode: None,
6347            locking_access: None,
6348            copy_grants: false,
6349            comment: None,
6350            tags: Vec::new(),
6351            options: Vec::new(),
6352            build: None,
6353            refresh: None,
6354            schema: None,
6355            unique_key: None,
6356            no_schema_binding: false,
6357            auto_refresh: None,
6358            on_cluster: None,
6359            to_table: None,
6360            table_properties: Vec::new(),
6361        }
6362    }
6363}
6364
6365/// DROP VIEW statement
6366#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6367#[cfg_attr(feature = "bindings", derive(TS))]
6368pub struct DropView {
6369    pub name: TableRef,
6370    pub if_exists: bool,
6371    pub materialized: bool,
6372}
6373
6374impl DropView {
6375    pub fn new(name: impl Into<String>) -> Self {
6376        Self {
6377            name: TableRef::new(name),
6378            if_exists: false,
6379            materialized: false,
6380        }
6381    }
6382}
6383
6384/// TRUNCATE TABLE statement
6385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6386#[cfg_attr(feature = "bindings", derive(TS))]
6387pub struct Truncate {
6388    /// Target of TRUNCATE (TABLE vs DATABASE)
6389    #[serde(default)]
6390    pub target: TruncateTarget,
6391    /// IF EXISTS clause
6392    #[serde(default)]
6393    pub if_exists: bool,
6394    pub table: TableRef,
6395    /// ClickHouse: ON CLUSTER clause for distributed DDL
6396    #[serde(default, skip_serializing_if = "Option::is_none")]
6397    pub on_cluster: Option<OnCluster>,
6398    pub cascade: bool,
6399    /// Additional tables for multi-table TRUNCATE
6400    #[serde(default)]
6401    pub extra_tables: Vec<TruncateTableEntry>,
6402    /// RESTART IDENTITY or CONTINUE IDENTITY
6403    #[serde(default)]
6404    pub identity: Option<TruncateIdentity>,
6405    /// RESTRICT option (alternative to CASCADE)
6406    #[serde(default)]
6407    pub restrict: bool,
6408    /// Hive PARTITION clause: PARTITION(key=value, ...)
6409    #[serde(default, skip_serializing_if = "Option::is_none")]
6410    pub partition: Option<Box<Expression>>,
6411}
6412
6413/// A table entry in a TRUNCATE statement, with optional ONLY modifier and * suffix
6414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6415#[cfg_attr(feature = "bindings", derive(TS))]
6416pub struct TruncateTableEntry {
6417    pub table: TableRef,
6418    /// Whether the table has a * suffix (inherit children)
6419    #[serde(default)]
6420    pub star: bool,
6421}
6422
6423/// TRUNCATE target type
6424#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6425#[cfg_attr(feature = "bindings", derive(TS))]
6426pub enum TruncateTarget {
6427    Table,
6428    Database,
6429}
6430
6431impl Default for TruncateTarget {
6432    fn default() -> Self {
6433        TruncateTarget::Table
6434    }
6435}
6436
6437/// TRUNCATE identity option
6438#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6439#[cfg_attr(feature = "bindings", derive(TS))]
6440pub enum TruncateIdentity {
6441    Restart,
6442    Continue,
6443}
6444
6445impl Truncate {
6446    pub fn new(table: impl Into<String>) -> Self {
6447        Self {
6448            target: TruncateTarget::Table,
6449            if_exists: false,
6450            table: TableRef::new(table),
6451            on_cluster: None,
6452            cascade: false,
6453            extra_tables: Vec::new(),
6454            identity: None,
6455            restrict: false,
6456            partition: None,
6457        }
6458    }
6459}
6460
6461/// USE statement (USE database, USE ROLE, USE WAREHOUSE, USE CATALOG, USE SCHEMA)
6462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6463#[cfg_attr(feature = "bindings", derive(TS))]
6464pub struct Use {
6465    /// The kind of object (DATABASE, SCHEMA, ROLE, WAREHOUSE, CATALOG, or None for default)
6466    pub kind: Option<UseKind>,
6467    /// The name of the object
6468    pub this: Identifier,
6469}
6470
6471/// Kind of USE statement
6472#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6473#[cfg_attr(feature = "bindings", derive(TS))]
6474pub enum UseKind {
6475    Database,
6476    Schema,
6477    Role,
6478    Warehouse,
6479    Catalog,
6480    /// Snowflake: USE SECONDARY ROLES ALL|NONE
6481    SecondaryRoles,
6482}
6483
6484/// SET variable statement
6485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6486#[cfg_attr(feature = "bindings", derive(TS))]
6487pub struct SetStatement {
6488    /// The items being set
6489    pub items: Vec<SetItem>,
6490}
6491
6492/// A single SET item (variable assignment)
6493#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6494#[cfg_attr(feature = "bindings", derive(TS))]
6495pub struct SetItem {
6496    /// The variable name
6497    pub name: Expression,
6498    /// The value to set
6499    pub value: Expression,
6500    /// Kind: None for plain SET, Some("GLOBAL") for SET GLOBAL, etc.
6501    pub kind: Option<String>,
6502    /// Whether the SET item was parsed without an = sign (TSQL: SET KEY VALUE)
6503    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
6504    pub no_equals: bool,
6505}
6506
6507/// CACHE TABLE statement (Spark)
6508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6509#[cfg_attr(feature = "bindings", derive(TS))]
6510pub struct Cache {
6511    /// The table to cache
6512    pub table: Identifier,
6513    /// LAZY keyword - defer caching until first use
6514    pub lazy: bool,
6515    /// Optional OPTIONS clause (key-value pairs)
6516    pub options: Vec<(Expression, Expression)>,
6517    /// Optional AS clause with query
6518    pub query: Option<Expression>,
6519}
6520
6521/// UNCACHE TABLE statement (Spark)
6522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6523#[cfg_attr(feature = "bindings", derive(TS))]
6524pub struct Uncache {
6525    /// The table to uncache
6526    pub table: Identifier,
6527    /// IF EXISTS clause
6528    pub if_exists: bool,
6529}
6530
6531/// LOAD DATA statement (Hive)
6532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6533#[cfg_attr(feature = "bindings", derive(TS))]
6534pub struct LoadData {
6535    /// LOCAL keyword - load from local filesystem
6536    pub local: bool,
6537    /// The path to load data from (INPATH value)
6538    pub inpath: String,
6539    /// Whether to overwrite existing data
6540    pub overwrite: bool,
6541    /// The target table
6542    pub table: Expression,
6543    /// Optional PARTITION clause with key-value pairs
6544    pub partition: Vec<(Identifier, Expression)>,
6545    /// Optional INPUTFORMAT clause
6546    pub input_format: Option<String>,
6547    /// Optional SERDE clause
6548    pub serde: Option<String>,
6549}
6550
6551/// PRAGMA statement (SQLite)
6552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6553#[cfg_attr(feature = "bindings", derive(TS))]
6554pub struct Pragma {
6555    /// Optional schema prefix (e.g., "schema" in "schema.pragma_name")
6556    pub schema: Option<Identifier>,
6557    /// The pragma name
6558    pub name: Identifier,
6559    /// Optional value for assignment (PRAGMA name = value)
6560    pub value: Option<Expression>,
6561    /// Optional arguments for function-style pragmas (PRAGMA name(arg))
6562    pub args: Vec<Expression>,
6563}
6564
6565/// A privilege with optional column list for GRANT/REVOKE
6566/// Examples: SELECT, UPDATE(col1, col2), ALL(col1, col2, col3)
6567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6568#[cfg_attr(feature = "bindings", derive(TS))]
6569pub struct Privilege {
6570    /// The privilege name (e.g., SELECT, INSERT, UPDATE, ALL)
6571    pub name: String,
6572    /// Optional column list for column-level privileges (e.g., UPDATE(col1, col2))
6573    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6574    pub columns: Vec<String>,
6575}
6576
6577/// Principal in GRANT/REVOKE (user, role, etc.)
6578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6579#[cfg_attr(feature = "bindings", derive(TS))]
6580pub struct GrantPrincipal {
6581    /// The name of the principal
6582    pub name: Identifier,
6583    /// Whether prefixed with ROLE keyword
6584    pub is_role: bool,
6585    /// Whether prefixed with GROUP keyword (Redshift)
6586    #[serde(default)]
6587    pub is_group: bool,
6588}
6589
6590/// GRANT statement
6591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6592#[cfg_attr(feature = "bindings", derive(TS))]
6593pub struct Grant {
6594    /// Privileges to grant (e.g., SELECT, INSERT, UPDATE(col1, col2))
6595    pub privileges: Vec<Privilege>,
6596    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6597    pub kind: Option<String>,
6598    /// The object to grant on
6599    pub securable: Identifier,
6600    /// Function parameter types (for FUNCTION kind)
6601    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6602    pub function_params: Vec<String>,
6603    /// The grantees
6604    pub principals: Vec<GrantPrincipal>,
6605    /// WITH GRANT OPTION
6606    pub grant_option: bool,
6607    /// TSQL: AS principal (the grantor role)
6608    #[serde(default, skip_serializing_if = "Option::is_none")]
6609    pub as_principal: Option<Identifier>,
6610}
6611
6612/// REVOKE statement
6613#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6614#[cfg_attr(feature = "bindings", derive(TS))]
6615pub struct Revoke {
6616    /// Privileges to revoke (e.g., SELECT, INSERT, UPDATE(col1, col2))
6617    pub privileges: Vec<Privilege>,
6618    /// Object kind (TABLE, SCHEMA, FUNCTION, etc.)
6619    pub kind: Option<String>,
6620    /// The object to revoke from
6621    pub securable: Identifier,
6622    /// Function parameter types (for FUNCTION kind)
6623    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6624    pub function_params: Vec<String>,
6625    /// The grantees
6626    pub principals: Vec<GrantPrincipal>,
6627    /// GRANT OPTION FOR
6628    pub grant_option: bool,
6629    /// CASCADE
6630    pub cascade: bool,
6631    /// RESTRICT
6632    #[serde(default)]
6633    pub restrict: bool,
6634}
6635
6636/// COMMENT ON statement
6637#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6638#[cfg_attr(feature = "bindings", derive(TS))]
6639pub struct Comment {
6640    /// The object being commented on
6641    pub this: Expression,
6642    /// The object kind (COLUMN, TABLE, DATABASE, etc.)
6643    pub kind: String,
6644    /// The comment text expression
6645    pub expression: Expression,
6646    /// IF EXISTS clause
6647    pub exists: bool,
6648    /// MATERIALIZED keyword
6649    pub materialized: bool,
6650}
6651
6652// ============================================================================
6653// Phase 4: Additional DDL Statements
6654// ============================================================================
6655
6656/// ALTER VIEW statement
6657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6658#[cfg_attr(feature = "bindings", derive(TS))]
6659pub struct AlterView {
6660    pub name: TableRef,
6661    pub actions: Vec<AlterViewAction>,
6662    /// MySQL: ALGORITHM = MERGE|TEMPTABLE|UNDEFINED
6663    #[serde(default, skip_serializing_if = "Option::is_none")]
6664    pub algorithm: Option<String>,
6665    /// MySQL: DEFINER = 'user'@'host'
6666    #[serde(default, skip_serializing_if = "Option::is_none")]
6667    pub definer: Option<String>,
6668    /// MySQL: SQL SECURITY = DEFINER|INVOKER
6669    #[serde(default, skip_serializing_if = "Option::is_none")]
6670    pub sql_security: Option<String>,
6671    /// TSQL: WITH option (SCHEMABINDING, ENCRYPTION, VIEW_METADATA)
6672    #[serde(default, skip_serializing_if = "Option::is_none")]
6673    pub with_option: Option<String>,
6674    /// Hive: Column aliases with optional comments: (c1 COMMENT 'text', c2)
6675    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6676    pub columns: Vec<ViewColumn>,
6677}
6678
6679/// Actions for ALTER VIEW
6680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6681#[cfg_attr(feature = "bindings", derive(TS))]
6682pub enum AlterViewAction {
6683    /// Rename the view
6684    Rename(TableRef),
6685    /// Change owner
6686    OwnerTo(Identifier),
6687    /// Set schema
6688    SetSchema(Identifier),
6689    /// Set authorization (Trino/Presto)
6690    SetAuthorization(String),
6691    /// Alter column
6692    AlterColumn {
6693        name: Identifier,
6694        action: AlterColumnAction,
6695    },
6696    /// Redefine view as query (SELECT, UNION, etc.)
6697    AsSelect(Box<Expression>),
6698    /// Hive: SET TBLPROPERTIES ('key'='value', ...)
6699    SetTblproperties(Vec<(String, String)>),
6700    /// Hive: UNSET TBLPROPERTIES ('key1', 'key2', ...)
6701    UnsetTblproperties(Vec<String>),
6702}
6703
6704impl AlterView {
6705    pub fn new(name: impl Into<String>) -> Self {
6706        Self {
6707            name: TableRef::new(name),
6708            actions: Vec::new(),
6709            algorithm: None,
6710            definer: None,
6711            sql_security: None,
6712            with_option: None,
6713            columns: Vec::new(),
6714        }
6715    }
6716}
6717
6718/// ALTER INDEX statement
6719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6720#[cfg_attr(feature = "bindings", derive(TS))]
6721pub struct AlterIndex {
6722    pub name: Identifier,
6723    pub table: Option<TableRef>,
6724    pub actions: Vec<AlterIndexAction>,
6725}
6726
6727/// Actions for ALTER INDEX
6728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6729#[cfg_attr(feature = "bindings", derive(TS))]
6730pub enum AlterIndexAction {
6731    /// Rename the index
6732    Rename(Identifier),
6733    /// Set tablespace
6734    SetTablespace(Identifier),
6735    /// Set visibility (MySQL)
6736    Visible(bool),
6737}
6738
6739impl AlterIndex {
6740    pub fn new(name: impl Into<String>) -> Self {
6741        Self {
6742            name: Identifier::new(name),
6743            table: None,
6744            actions: Vec::new(),
6745        }
6746    }
6747}
6748
6749/// CREATE SCHEMA statement
6750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6751#[cfg_attr(feature = "bindings", derive(TS))]
6752pub struct CreateSchema {
6753    pub name: Identifier,
6754    pub if_not_exists: bool,
6755    pub authorization: Option<Identifier>,
6756    #[serde(default)]
6757    pub clone_from: Option<Identifier>,
6758    /// AT/BEFORE clause for time travel (Snowflake)
6759    #[serde(default)]
6760    pub at_clause: Option<Expression>,
6761    /// Schema properties like DEFAULT COLLATE
6762    #[serde(default)]
6763    pub properties: Vec<Expression>,
6764    /// Leading comments before the statement
6765    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6766    pub leading_comments: Vec<String>,
6767}
6768
6769impl CreateSchema {
6770    pub fn new(name: impl Into<String>) -> Self {
6771        Self {
6772            name: Identifier::new(name),
6773            if_not_exists: false,
6774            authorization: None,
6775            clone_from: None,
6776            at_clause: None,
6777            properties: Vec::new(),
6778            leading_comments: Vec::new(),
6779        }
6780    }
6781}
6782
6783/// DROP SCHEMA statement
6784#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6785#[cfg_attr(feature = "bindings", derive(TS))]
6786pub struct DropSchema {
6787    pub name: Identifier,
6788    pub if_exists: bool,
6789    pub cascade: bool,
6790}
6791
6792impl DropSchema {
6793    pub fn new(name: impl Into<String>) -> Self {
6794        Self {
6795            name: Identifier::new(name),
6796            if_exists: false,
6797            cascade: false,
6798        }
6799    }
6800}
6801
6802/// DROP NAMESPACE statement (Spark/Databricks - alias for DROP SCHEMA)
6803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6804#[cfg_attr(feature = "bindings", derive(TS))]
6805pub struct DropNamespace {
6806    pub name: Identifier,
6807    pub if_exists: bool,
6808    pub cascade: bool,
6809}
6810
6811impl DropNamespace {
6812    pub fn new(name: impl Into<String>) -> Self {
6813        Self {
6814            name: Identifier::new(name),
6815            if_exists: false,
6816            cascade: false,
6817        }
6818    }
6819}
6820
6821/// CREATE DATABASE statement
6822#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6823#[cfg_attr(feature = "bindings", derive(TS))]
6824pub struct CreateDatabase {
6825    pub name: Identifier,
6826    pub if_not_exists: bool,
6827    pub options: Vec<DatabaseOption>,
6828    /// Snowflake CLONE source
6829    #[serde(default)]
6830    pub clone_from: Option<Identifier>,
6831    /// AT/BEFORE clause for time travel (Snowflake)
6832    #[serde(default)]
6833    pub at_clause: Option<Expression>,
6834}
6835
6836/// Database option
6837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6838#[cfg_attr(feature = "bindings", derive(TS))]
6839pub enum DatabaseOption {
6840    CharacterSet(String),
6841    Collate(String),
6842    Owner(Identifier),
6843    Template(Identifier),
6844    Encoding(String),
6845    Location(String),
6846}
6847
6848impl CreateDatabase {
6849    pub fn new(name: impl Into<String>) -> Self {
6850        Self {
6851            name: Identifier::new(name),
6852            if_not_exists: false,
6853            options: Vec::new(),
6854            clone_from: None,
6855            at_clause: None,
6856        }
6857    }
6858}
6859
6860/// DROP DATABASE statement
6861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6862#[cfg_attr(feature = "bindings", derive(TS))]
6863pub struct DropDatabase {
6864    pub name: Identifier,
6865    pub if_exists: bool,
6866}
6867
6868impl DropDatabase {
6869    pub fn new(name: impl Into<String>) -> Self {
6870        Self {
6871            name: Identifier::new(name),
6872            if_exists: false,
6873        }
6874    }
6875}
6876
6877/// CREATE FUNCTION statement
6878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6879#[cfg_attr(feature = "bindings", derive(TS))]
6880pub struct CreateFunction {
6881    pub name: TableRef,
6882    pub parameters: Vec<FunctionParameter>,
6883    pub return_type: Option<DataType>,
6884    pub body: Option<FunctionBody>,
6885    pub or_replace: bool,
6886    pub if_not_exists: bool,
6887    pub temporary: bool,
6888    pub language: Option<String>,
6889    pub deterministic: Option<bool>,
6890    pub returns_null_on_null_input: Option<bool>,
6891    pub security: Option<FunctionSecurity>,
6892    /// Whether parentheses were present in the original syntax
6893    #[serde(default = "default_true")]
6894    pub has_parens: bool,
6895    /// SQL data access characteristic (CONTAINS SQL, READS SQL DATA, etc.)
6896    #[serde(default)]
6897    pub sql_data_access: Option<SqlDataAccess>,
6898    /// TSQL: RETURNS @var TABLE (col_defs) - stores the variable name and column definitions as raw string
6899    #[serde(default, skip_serializing_if = "Option::is_none")]
6900    pub returns_table_body: Option<String>,
6901    /// True if LANGUAGE clause appears before RETURNS clause
6902    #[serde(default)]
6903    pub language_first: bool,
6904    /// PostgreSQL SET options: SET key = value, SET key FROM CURRENT
6905    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6906    pub set_options: Vec<FunctionSetOption>,
6907    /// True if STRICT was used instead of RETURNS NULL ON NULL INPUT
6908    #[serde(default)]
6909    pub strict: bool,
6910    /// BigQuery: OPTIONS (key=value, ...)
6911    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6912    pub options: Vec<Expression>,
6913    /// BigQuery: True if this is a TABLE FUNCTION (CREATE TABLE FUNCTION)
6914    #[serde(default)]
6915    pub is_table_function: bool,
6916    /// Original order of function properties (SET, AS, LANGUAGE, etc.)
6917    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6918    pub property_order: Vec<FunctionPropertyKind>,
6919    /// Databricks: ENVIRONMENT (dependencies = '...', environment_version = '...')
6920    #[serde(default, skip_serializing_if = "Vec::is_empty")]
6921    pub environment: Vec<Expression>,
6922}
6923
6924/// A SET option in CREATE FUNCTION (PostgreSQL)
6925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6926#[cfg_attr(feature = "bindings", derive(TS))]
6927pub struct FunctionSetOption {
6928    pub name: String,
6929    pub value: FunctionSetValue,
6930}
6931
6932/// The value of a SET option
6933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6934#[cfg_attr(feature = "bindings", derive(TS))]
6935pub enum FunctionSetValue {
6936    /// SET key = value (use_to = false) or SET key TO value (use_to = true)
6937    Value { value: String, use_to: bool },
6938    /// SET key FROM CURRENT
6939    FromCurrent,
6940}
6941
6942/// SQL data access characteristics for functions
6943#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6944#[cfg_attr(feature = "bindings", derive(TS))]
6945pub enum SqlDataAccess {
6946    /// NO SQL
6947    NoSql,
6948    /// CONTAINS SQL
6949    ContainsSql,
6950    /// READS SQL DATA
6951    ReadsSqlData,
6952    /// MODIFIES SQL DATA
6953    ModifiesSqlData,
6954}
6955
6956/// Types of properties in CREATE FUNCTION for tracking their original order
6957#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6958#[cfg_attr(feature = "bindings", derive(TS))]
6959pub enum FunctionPropertyKind {
6960    /// SET option
6961    Set,
6962    /// AS body
6963    As,
6964    /// LANGUAGE clause
6965    Language,
6966    /// IMMUTABLE/VOLATILE/STABLE (determinism)
6967    Determinism,
6968    /// CALLED ON NULL INPUT / RETURNS NULL ON NULL INPUT / STRICT
6969    NullInput,
6970    /// SECURITY DEFINER/INVOKER
6971    Security,
6972    /// SQL data access (CONTAINS SQL, READS SQL DATA, etc.)
6973    SqlDataAccess,
6974    /// OPTIONS clause (BigQuery)
6975    Options,
6976    /// ENVIRONMENT clause (Databricks)
6977    Environment,
6978}
6979
6980/// Function parameter
6981#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6982#[cfg_attr(feature = "bindings", derive(TS))]
6983pub struct FunctionParameter {
6984    pub name: Option<Identifier>,
6985    pub data_type: DataType,
6986    pub mode: Option<ParameterMode>,
6987    pub default: Option<Expression>,
6988    /// Original text of the mode keyword for case-preserving output (e.g., "inout", "VARIADIC")
6989    #[serde(default, skip_serializing_if = "Option::is_none")]
6990    pub mode_text: Option<String>,
6991}
6992
6993/// Parameter mode (IN, OUT, INOUT, VARIADIC)
6994#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6995#[cfg_attr(feature = "bindings", derive(TS))]
6996pub enum ParameterMode {
6997    In,
6998    Out,
6999    InOut,
7000    Variadic,
7001}
7002
7003/// Function body
7004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7005#[cfg_attr(feature = "bindings", derive(TS))]
7006pub enum FunctionBody {
7007    /// AS $$ ... $$ (dollar-quoted)
7008    Block(String),
7009    /// AS 'string' (single-quoted string literal body)
7010    StringLiteral(String),
7011    /// AS 'expression'
7012    Expression(Expression),
7013    /// EXTERNAL NAME 'library'
7014    External(String),
7015    /// RETURN expression
7016    Return(Expression),
7017    /// BEGIN ... END block with parsed statements
7018    Statements(Vec<Expression>),
7019    /// AS $$...$$ or $tag$...$tag$ (dollar-quoted with optional tag)
7020    /// Stores (content, optional_tag)
7021    DollarQuoted {
7022        content: String,
7023        tag: Option<String>,
7024    },
7025}
7026
7027/// Function security (DEFINER, INVOKER, or NONE)
7028#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7029#[cfg_attr(feature = "bindings", derive(TS))]
7030pub enum FunctionSecurity {
7031    Definer,
7032    Invoker,
7033    /// StarRocks/MySQL: SECURITY NONE
7034    None,
7035}
7036
7037impl CreateFunction {
7038    pub fn new(name: impl Into<String>) -> Self {
7039        Self {
7040            name: TableRef::new(name),
7041            parameters: Vec::new(),
7042            return_type: None,
7043            body: None,
7044            or_replace: false,
7045            if_not_exists: false,
7046            temporary: false,
7047            language: None,
7048            deterministic: None,
7049            returns_null_on_null_input: None,
7050            security: None,
7051            has_parens: true,
7052            sql_data_access: None,
7053            returns_table_body: None,
7054            language_first: false,
7055            set_options: Vec::new(),
7056            strict: false,
7057            options: Vec::new(),
7058            is_table_function: false,
7059            property_order: Vec::new(),
7060            environment: Vec::new(),
7061        }
7062    }
7063}
7064
7065/// DROP FUNCTION statement
7066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7067#[cfg_attr(feature = "bindings", derive(TS))]
7068pub struct DropFunction {
7069    pub name: TableRef,
7070    pub parameters: Option<Vec<DataType>>,
7071    pub if_exists: bool,
7072    pub cascade: bool,
7073}
7074
7075impl DropFunction {
7076    pub fn new(name: impl Into<String>) -> Self {
7077        Self {
7078            name: TableRef::new(name),
7079            parameters: None,
7080            if_exists: false,
7081            cascade: false,
7082        }
7083    }
7084}
7085
7086/// CREATE PROCEDURE statement
7087#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7088#[cfg_attr(feature = "bindings", derive(TS))]
7089pub struct CreateProcedure {
7090    pub name: TableRef,
7091    pub parameters: Vec<FunctionParameter>,
7092    pub body: Option<FunctionBody>,
7093    pub or_replace: bool,
7094    pub if_not_exists: bool,
7095    pub language: Option<String>,
7096    pub security: Option<FunctionSecurity>,
7097    /// Return type (Snowflake: RETURNS OBJECT, RETURNS VARCHAR, etc.)
7098    #[serde(default)]
7099    pub return_type: Option<DataType>,
7100    /// Execution context (EXECUTE AS CALLER, EXECUTE AS OWNER)
7101    #[serde(default)]
7102    pub execute_as: Option<String>,
7103    /// TSQL WITH options (ENCRYPTION, RECOMPILE, SCHEMABINDING, etc.)
7104    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7105    pub with_options: Vec<String>,
7106    /// Whether the parameter list had parentheses (false for TSQL procedures without parens)
7107    #[serde(default = "default_true", skip_serializing_if = "is_true")]
7108    pub has_parens: bool,
7109    /// Whether the short form PROC was used (instead of PROCEDURE)
7110    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
7111    pub use_proc_keyword: bool,
7112}
7113
7114impl CreateProcedure {
7115    pub fn new(name: impl Into<String>) -> Self {
7116        Self {
7117            name: TableRef::new(name),
7118            parameters: Vec::new(),
7119            body: None,
7120            or_replace: false,
7121            if_not_exists: false,
7122            language: None,
7123            security: None,
7124            return_type: None,
7125            execute_as: None,
7126            with_options: Vec::new(),
7127            has_parens: true,
7128            use_proc_keyword: false,
7129        }
7130    }
7131}
7132
7133/// DROP PROCEDURE statement
7134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7135#[cfg_attr(feature = "bindings", derive(TS))]
7136pub struct DropProcedure {
7137    pub name: TableRef,
7138    pub parameters: Option<Vec<DataType>>,
7139    pub if_exists: bool,
7140    pub cascade: bool,
7141}
7142
7143impl DropProcedure {
7144    pub fn new(name: impl Into<String>) -> Self {
7145        Self {
7146            name: TableRef::new(name),
7147            parameters: None,
7148            if_exists: false,
7149            cascade: false,
7150        }
7151    }
7152}
7153
7154/// Sequence property tag for ordering
7155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7156#[cfg_attr(feature = "bindings", derive(TS))]
7157pub enum SeqPropKind {
7158    Start,
7159    Increment,
7160    Minvalue,
7161    Maxvalue,
7162    Cache,
7163    NoCache,
7164    Cycle,
7165    NoCycle,
7166    OwnedBy,
7167    Order,
7168    NoOrder,
7169    Comment,
7170    /// SHARING=<value> (Oracle)
7171    Sharing,
7172    /// KEEP (Oracle)
7173    Keep,
7174    /// NOKEEP (Oracle)
7175    NoKeep,
7176    /// SCALE [EXTEND|NOEXTEND] (Oracle)
7177    Scale,
7178    /// NOSCALE (Oracle)
7179    NoScale,
7180    /// SHARD [EXTEND|NOEXTEND] (Oracle)
7181    Shard,
7182    /// NOSHARD (Oracle)
7183    NoShard,
7184    /// SESSION (Oracle)
7185    Session,
7186    /// GLOBAL (Oracle)
7187    Global,
7188    /// NOCACHE (single word, Oracle)
7189    NoCacheWord,
7190    /// NOCYCLE (single word, Oracle)
7191    NoCycleWord,
7192    /// NOMINVALUE (single word, Oracle)
7193    NoMinvalueWord,
7194    /// NOMAXVALUE (single word, Oracle)
7195    NoMaxvalueWord,
7196}
7197
7198/// CREATE SEQUENCE statement
7199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7200#[cfg_attr(feature = "bindings", derive(TS))]
7201pub struct CreateSequence {
7202    pub name: TableRef,
7203    pub if_not_exists: bool,
7204    pub temporary: bool,
7205    #[serde(default)]
7206    pub or_replace: bool,
7207    /// AS <type> clause (e.g., AS SMALLINT, AS BIGINT)
7208    #[serde(default, skip_serializing_if = "Option::is_none")]
7209    pub as_type: Option<DataType>,
7210    pub increment: Option<i64>,
7211    pub minvalue: Option<SequenceBound>,
7212    pub maxvalue: Option<SequenceBound>,
7213    pub start: Option<i64>,
7214    pub cache: Option<i64>,
7215    pub cycle: bool,
7216    pub owned_by: Option<TableRef>,
7217    /// Whether OWNED BY NONE was specified
7218    #[serde(default)]
7219    pub owned_by_none: bool,
7220    /// Snowflake: ORDER or NOORDER (true = ORDER, false = NOORDER, None = not specified)
7221    #[serde(default)]
7222    pub order: Option<bool>,
7223    /// Snowflake: COMMENT = 'value'
7224    #[serde(default)]
7225    pub comment: Option<String>,
7226    /// SHARING=<value> (Oracle)
7227    #[serde(default, skip_serializing_if = "Option::is_none")]
7228    pub sharing: Option<String>,
7229    /// SCALE modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SCALE
7230    #[serde(default, skip_serializing_if = "Option::is_none")]
7231    pub scale_modifier: Option<String>,
7232    /// SHARD modifier: Some("EXTEND"), Some("NOEXTEND"), Some("") for plain SHARD
7233    #[serde(default, skip_serializing_if = "Option::is_none")]
7234    pub shard_modifier: Option<String>,
7235    /// Tracks the order in which properties appeared in the source
7236    #[serde(default)]
7237    pub property_order: Vec<SeqPropKind>,
7238}
7239
7240/// Sequence bound (value or NO MINVALUE/NO MAXVALUE)
7241#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7242#[cfg_attr(feature = "bindings", derive(TS))]
7243pub enum SequenceBound {
7244    Value(i64),
7245    None,
7246}
7247
7248impl CreateSequence {
7249    pub fn new(name: impl Into<String>) -> Self {
7250        Self {
7251            name: TableRef::new(name),
7252            if_not_exists: false,
7253            temporary: false,
7254            or_replace: false,
7255            as_type: None,
7256            increment: None,
7257            minvalue: None,
7258            maxvalue: None,
7259            start: None,
7260            cache: None,
7261            cycle: false,
7262            owned_by: None,
7263            owned_by_none: false,
7264            order: None,
7265            comment: None,
7266            sharing: None,
7267            scale_modifier: None,
7268            shard_modifier: None,
7269            property_order: Vec::new(),
7270        }
7271    }
7272}
7273
7274/// DROP SEQUENCE statement
7275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7276#[cfg_attr(feature = "bindings", derive(TS))]
7277pub struct DropSequence {
7278    pub name: TableRef,
7279    pub if_exists: bool,
7280    pub cascade: bool,
7281}
7282
7283impl DropSequence {
7284    pub fn new(name: impl Into<String>) -> Self {
7285        Self {
7286            name: TableRef::new(name),
7287            if_exists: false,
7288            cascade: false,
7289        }
7290    }
7291}
7292
7293/// ALTER SEQUENCE statement
7294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7295#[cfg_attr(feature = "bindings", derive(TS))]
7296pub struct AlterSequence {
7297    pub name: TableRef,
7298    pub if_exists: bool,
7299    pub increment: Option<i64>,
7300    pub minvalue: Option<SequenceBound>,
7301    pub maxvalue: Option<SequenceBound>,
7302    pub start: Option<i64>,
7303    pub restart: Option<Option<i64>>,
7304    pub cache: Option<i64>,
7305    pub cycle: Option<bool>,
7306    pub owned_by: Option<Option<TableRef>>,
7307}
7308
7309impl AlterSequence {
7310    pub fn new(name: impl Into<String>) -> Self {
7311        Self {
7312            name: TableRef::new(name),
7313            if_exists: false,
7314            increment: None,
7315            minvalue: None,
7316            maxvalue: None,
7317            start: None,
7318            restart: None,
7319            cache: None,
7320            cycle: None,
7321            owned_by: None,
7322        }
7323    }
7324}
7325
7326/// CREATE TRIGGER statement
7327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7328#[cfg_attr(feature = "bindings", derive(TS))]
7329pub struct CreateTrigger {
7330    pub name: Identifier,
7331    pub table: TableRef,
7332    pub timing: TriggerTiming,
7333    pub events: Vec<TriggerEvent>,
7334    pub for_each: TriggerForEach,
7335    pub when: Option<Expression>,
7336    pub body: TriggerBody,
7337    pub or_replace: bool,
7338    pub constraint: bool,
7339    pub deferrable: Option<bool>,
7340    pub initially_deferred: Option<bool>,
7341    pub referencing: Option<TriggerReferencing>,
7342}
7343
7344/// Trigger timing (BEFORE, AFTER, INSTEAD OF)
7345#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7346#[cfg_attr(feature = "bindings", derive(TS))]
7347pub enum TriggerTiming {
7348    Before,
7349    After,
7350    InsteadOf,
7351}
7352
7353/// Trigger event (INSERT, UPDATE, DELETE, TRUNCATE)
7354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7355#[cfg_attr(feature = "bindings", derive(TS))]
7356pub enum TriggerEvent {
7357    Insert,
7358    Update(Option<Vec<Identifier>>),
7359    Delete,
7360    Truncate,
7361}
7362
7363/// Trigger FOR EACH clause
7364#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7365#[cfg_attr(feature = "bindings", derive(TS))]
7366pub enum TriggerForEach {
7367    Row,
7368    Statement,
7369}
7370
7371/// Trigger body
7372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7373#[cfg_attr(feature = "bindings", derive(TS))]
7374pub enum TriggerBody {
7375    /// EXECUTE FUNCTION/PROCEDURE name(args)
7376    Execute {
7377        function: TableRef,
7378        args: Vec<Expression>,
7379    },
7380    /// BEGIN ... END block
7381    Block(String),
7382}
7383
7384/// Trigger REFERENCING clause
7385#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7386#[cfg_attr(feature = "bindings", derive(TS))]
7387pub struct TriggerReferencing {
7388    pub old_table: Option<Identifier>,
7389    pub new_table: Option<Identifier>,
7390    pub old_row: Option<Identifier>,
7391    pub new_row: Option<Identifier>,
7392}
7393
7394impl CreateTrigger {
7395    pub fn new(name: impl Into<String>, table: impl Into<String>) -> Self {
7396        Self {
7397            name: Identifier::new(name),
7398            table: TableRef::new(table),
7399            timing: TriggerTiming::Before,
7400            events: Vec::new(),
7401            for_each: TriggerForEach::Row,
7402            when: None,
7403            body: TriggerBody::Execute {
7404                function: TableRef::new(""),
7405                args: Vec::new(),
7406            },
7407            or_replace: false,
7408            constraint: false,
7409            deferrable: None,
7410            initially_deferred: None,
7411            referencing: None,
7412        }
7413    }
7414}
7415
7416/// DROP TRIGGER statement
7417#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7418#[cfg_attr(feature = "bindings", derive(TS))]
7419pub struct DropTrigger {
7420    pub name: Identifier,
7421    pub table: Option<TableRef>,
7422    pub if_exists: bool,
7423    pub cascade: bool,
7424}
7425
7426impl DropTrigger {
7427    pub fn new(name: impl Into<String>) -> Self {
7428        Self {
7429            name: Identifier::new(name),
7430            table: None,
7431            if_exists: false,
7432            cascade: false,
7433        }
7434    }
7435}
7436
7437/// CREATE TYPE statement
7438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7439#[cfg_attr(feature = "bindings", derive(TS))]
7440pub struct CreateType {
7441    pub name: TableRef,
7442    pub definition: TypeDefinition,
7443    pub if_not_exists: bool,
7444}
7445
7446/// Type definition
7447#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7448#[cfg_attr(feature = "bindings", derive(TS))]
7449pub enum TypeDefinition {
7450    /// ENUM type: CREATE TYPE name AS ENUM ('val1', 'val2', ...)
7451    Enum(Vec<String>),
7452    /// Composite type: CREATE TYPE name AS (field1 type1, field2 type2, ...)
7453    Composite(Vec<TypeAttribute>),
7454    /// Range type: CREATE TYPE name AS RANGE (SUBTYPE = type, ...)
7455    Range {
7456        subtype: DataType,
7457        subtype_diff: Option<String>,
7458        canonical: Option<String>,
7459    },
7460    /// Base type (for advanced usage)
7461    Base {
7462        input: String,
7463        output: String,
7464        internallength: Option<i32>,
7465    },
7466    /// Domain type
7467    Domain {
7468        base_type: DataType,
7469        default: Option<Expression>,
7470        constraints: Vec<DomainConstraint>,
7471    },
7472}
7473
7474/// Type attribute for composite types
7475#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7476#[cfg_attr(feature = "bindings", derive(TS))]
7477pub struct TypeAttribute {
7478    pub name: Identifier,
7479    pub data_type: DataType,
7480    pub collate: Option<Identifier>,
7481}
7482
7483/// Domain constraint
7484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7485#[cfg_attr(feature = "bindings", derive(TS))]
7486pub struct DomainConstraint {
7487    pub name: Option<Identifier>,
7488    pub check: Expression,
7489}
7490
7491impl CreateType {
7492    pub fn new_enum(name: impl Into<String>, values: Vec<String>) -> Self {
7493        Self {
7494            name: TableRef::new(name),
7495            definition: TypeDefinition::Enum(values),
7496            if_not_exists: false,
7497        }
7498    }
7499
7500    pub fn new_composite(name: impl Into<String>, attributes: Vec<TypeAttribute>) -> Self {
7501        Self {
7502            name: TableRef::new(name),
7503            definition: TypeDefinition::Composite(attributes),
7504            if_not_exists: false,
7505        }
7506    }
7507}
7508
7509/// DROP TYPE statement
7510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7511#[cfg_attr(feature = "bindings", derive(TS))]
7512pub struct DropType {
7513    pub name: TableRef,
7514    pub if_exists: bool,
7515    pub cascade: bool,
7516}
7517
7518impl DropType {
7519    pub fn new(name: impl Into<String>) -> Self {
7520        Self {
7521            name: TableRef::new(name),
7522            if_exists: false,
7523            cascade: false,
7524        }
7525    }
7526}
7527
7528/// DESCRIBE statement - shows table structure or query plan
7529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7530#[cfg_attr(feature = "bindings", derive(TS))]
7531pub struct Describe {
7532    /// The target to describe (table name or query)
7533    pub target: Expression,
7534    /// EXTENDED format
7535    pub extended: bool,
7536    /// FORMATTED format
7537    pub formatted: bool,
7538    /// Object kind (e.g., "SEMANTIC VIEW", "TABLE", etc.)
7539    #[serde(default)]
7540    pub kind: Option<String>,
7541    /// Properties like type=stage
7542    #[serde(default)]
7543    pub properties: Vec<(String, String)>,
7544    /// Style keyword (e.g., "ANALYZE", "HISTORY")
7545    #[serde(default, skip_serializing_if = "Option::is_none")]
7546    pub style: Option<String>,
7547    /// Partition specification for DESCRIBE PARTITION
7548    #[serde(default)]
7549    pub partition: Option<Box<Expression>>,
7550    /// Leading comments before the statement
7551    #[serde(default)]
7552    pub leading_comments: Vec<String>,
7553    /// AS JSON suffix (Databricks)
7554    #[serde(default)]
7555    pub as_json: bool,
7556}
7557
7558impl Describe {
7559    pub fn new(target: Expression) -> Self {
7560        Self {
7561            target,
7562            extended: false,
7563            formatted: false,
7564            kind: None,
7565            properties: Vec::new(),
7566            style: None,
7567            partition: None,
7568            leading_comments: Vec::new(),
7569            as_json: false,
7570        }
7571    }
7572}
7573
7574/// SHOW statement - displays database objects
7575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7576#[cfg_attr(feature = "bindings", derive(TS))]
7577pub struct Show {
7578    /// The thing to show (DATABASES, TABLES, SCHEMAS, etc.)
7579    pub this: String,
7580    /// Whether TERSE was specified
7581    #[serde(default)]
7582    pub terse: bool,
7583    /// Whether HISTORY was specified
7584    #[serde(default)]
7585    pub history: bool,
7586    /// LIKE pattern
7587    pub like: Option<Expression>,
7588    /// IN scope kind (ACCOUNT, DATABASE, SCHEMA, TABLE)
7589    pub scope_kind: Option<String>,
7590    /// IN scope object
7591    pub scope: Option<Expression>,
7592    /// STARTS WITH pattern
7593    pub starts_with: Option<Expression>,
7594    /// LIMIT clause
7595    pub limit: Option<Box<Limit>>,
7596    /// FROM clause (for specific object)
7597    pub from: Option<Expression>,
7598    /// WHERE clause (MySQL: SHOW STATUS WHERE ...)
7599    #[serde(default, skip_serializing_if = "Option::is_none")]
7600    pub where_clause: Option<Expression>,
7601    /// FOR target (MySQL: SHOW GRANTS FOR user, SHOW PROFILE ... FOR QUERY n)
7602    #[serde(default, skip_serializing_if = "Option::is_none")]
7603    pub for_target: Option<Expression>,
7604    /// Second FROM clause (MySQL: SHOW COLUMNS FROM tbl FROM db)
7605    #[serde(default, skip_serializing_if = "Option::is_none")]
7606    pub db: Option<Expression>,
7607    /// Target identifier (MySQL: engine name in SHOW ENGINE, table in SHOW COLUMNS FROM)
7608    #[serde(default, skip_serializing_if = "Option::is_none")]
7609    pub target: Option<Expression>,
7610    /// MUTEX flag for SHOW ENGINE (true=MUTEX, false=STATUS, None=neither)
7611    #[serde(default, skip_serializing_if = "Option::is_none")]
7612    pub mutex: Option<bool>,
7613    /// WITH PRIVILEGES clause (Snowflake: SHOW ... WITH PRIVILEGES USAGE, MODIFY)
7614    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7615    pub privileges: Vec<String>,
7616}
7617
7618impl Show {
7619    pub fn new(this: impl Into<String>) -> Self {
7620        Self {
7621            this: this.into(),
7622            terse: false,
7623            history: false,
7624            like: None,
7625            scope_kind: None,
7626            scope: None,
7627            starts_with: None,
7628            limit: None,
7629            from: None,
7630            where_clause: None,
7631            for_target: None,
7632            db: None,
7633            target: None,
7634            mutex: None,
7635            privileges: Vec::new(),
7636        }
7637    }
7638}
7639
7640/// Represent an explicit parenthesized expression for grouping precedence.
7641///
7642/// Preserves user-written parentheses so that `(a + b) * c` round-trips
7643/// correctly instead of being flattened to `a + b * c`.
7644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7645#[cfg_attr(feature = "bindings", derive(TS))]
7646pub struct Paren {
7647    /// The inner expression wrapped by parentheses.
7648    pub this: Expression,
7649    #[serde(default)]
7650    pub trailing_comments: Vec<String>,
7651}
7652
7653/// Expression annotated with trailing comments (for round-trip preservation)
7654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7655#[cfg_attr(feature = "bindings", derive(TS))]
7656pub struct Annotated {
7657    pub this: Expression,
7658    pub trailing_comments: Vec<String>,
7659}
7660
7661// === BATCH GENERATED STRUCT DEFINITIONS ===
7662// Generated from Python sqlglot expressions.py
7663
7664/// Refresh
7665#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7666#[cfg_attr(feature = "bindings", derive(TS))]
7667pub struct Refresh {
7668    pub this: Box<Expression>,
7669    pub kind: String,
7670}
7671
7672/// LockingStatement
7673#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7674#[cfg_attr(feature = "bindings", derive(TS))]
7675pub struct LockingStatement {
7676    pub this: Box<Expression>,
7677    pub expression: Box<Expression>,
7678}
7679
7680/// SequenceProperties
7681#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7682#[cfg_attr(feature = "bindings", derive(TS))]
7683pub struct SequenceProperties {
7684    #[serde(default)]
7685    pub increment: Option<Box<Expression>>,
7686    #[serde(default)]
7687    pub minvalue: Option<Box<Expression>>,
7688    #[serde(default)]
7689    pub maxvalue: Option<Box<Expression>>,
7690    #[serde(default)]
7691    pub cache: Option<Box<Expression>>,
7692    #[serde(default)]
7693    pub start: Option<Box<Expression>>,
7694    #[serde(default)]
7695    pub owned: Option<Box<Expression>>,
7696    #[serde(default)]
7697    pub options: Vec<Expression>,
7698}
7699
7700/// TruncateTable
7701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7702#[cfg_attr(feature = "bindings", derive(TS))]
7703pub struct TruncateTable {
7704    #[serde(default)]
7705    pub expressions: Vec<Expression>,
7706    #[serde(default)]
7707    pub is_database: Option<Box<Expression>>,
7708    #[serde(default)]
7709    pub exists: bool,
7710    #[serde(default)]
7711    pub only: Option<Box<Expression>>,
7712    #[serde(default)]
7713    pub cluster: Option<Box<Expression>>,
7714    #[serde(default)]
7715    pub identity: Option<Box<Expression>>,
7716    #[serde(default)]
7717    pub option: Option<Box<Expression>>,
7718    #[serde(default)]
7719    pub partition: Option<Box<Expression>>,
7720}
7721
7722/// Clone
7723#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7724#[cfg_attr(feature = "bindings", derive(TS))]
7725pub struct Clone {
7726    pub this: Box<Expression>,
7727    #[serde(default)]
7728    pub shallow: Option<Box<Expression>>,
7729    #[serde(default)]
7730    pub copy: Option<Box<Expression>>,
7731}
7732
7733/// Attach
7734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7735#[cfg_attr(feature = "bindings", derive(TS))]
7736pub struct Attach {
7737    pub this: Box<Expression>,
7738    #[serde(default)]
7739    pub exists: bool,
7740    #[serde(default)]
7741    pub expressions: Vec<Expression>,
7742}
7743
7744/// Detach
7745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7746#[cfg_attr(feature = "bindings", derive(TS))]
7747pub struct Detach {
7748    pub this: Box<Expression>,
7749    #[serde(default)]
7750    pub exists: bool,
7751}
7752
7753/// Install
7754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7755#[cfg_attr(feature = "bindings", derive(TS))]
7756pub struct Install {
7757    pub this: Box<Expression>,
7758    #[serde(default)]
7759    pub from_: Option<Box<Expression>>,
7760    #[serde(default)]
7761    pub force: Option<Box<Expression>>,
7762}
7763
7764/// Summarize
7765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7766#[cfg_attr(feature = "bindings", derive(TS))]
7767pub struct Summarize {
7768    pub this: Box<Expression>,
7769    #[serde(default)]
7770    pub table: Option<Box<Expression>>,
7771}
7772
7773/// Declare
7774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7775#[cfg_attr(feature = "bindings", derive(TS))]
7776pub struct Declare {
7777    #[serde(default)]
7778    pub expressions: Vec<Expression>,
7779}
7780
7781/// DeclareItem
7782#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7783#[cfg_attr(feature = "bindings", derive(TS))]
7784pub struct DeclareItem {
7785    pub this: Box<Expression>,
7786    #[serde(default)]
7787    pub kind: Option<String>,
7788    #[serde(default)]
7789    pub default: Option<Box<Expression>>,
7790    #[serde(default)]
7791    pub has_as: bool,
7792    /// BigQuery: additional variable names in multi-variable DECLARE (DECLARE X, Y, Z INT64)
7793    #[serde(default, skip_serializing_if = "Vec::is_empty")]
7794    pub additional_names: Vec<Expression>,
7795}
7796
7797/// Set
7798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7799#[cfg_attr(feature = "bindings", derive(TS))]
7800pub struct Set {
7801    #[serde(default)]
7802    pub expressions: Vec<Expression>,
7803    #[serde(default)]
7804    pub unset: Option<Box<Expression>>,
7805    #[serde(default)]
7806    pub tag: Option<Box<Expression>>,
7807}
7808
7809/// Heredoc
7810#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7811#[cfg_attr(feature = "bindings", derive(TS))]
7812pub struct Heredoc {
7813    pub this: Box<Expression>,
7814    #[serde(default)]
7815    pub tag: Option<Box<Expression>>,
7816}
7817
7818/// QueryBand
7819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7820#[cfg_attr(feature = "bindings", derive(TS))]
7821pub struct QueryBand {
7822    pub this: Box<Expression>,
7823    #[serde(default)]
7824    pub scope: Option<Box<Expression>>,
7825    #[serde(default)]
7826    pub update: Option<Box<Expression>>,
7827}
7828
7829/// UserDefinedFunction
7830#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7831#[cfg_attr(feature = "bindings", derive(TS))]
7832pub struct UserDefinedFunction {
7833    pub this: Box<Expression>,
7834    #[serde(default)]
7835    pub expressions: Vec<Expression>,
7836    #[serde(default)]
7837    pub wrapped: Option<Box<Expression>>,
7838}
7839
7840/// RecursiveWithSearch
7841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7842#[cfg_attr(feature = "bindings", derive(TS))]
7843pub struct RecursiveWithSearch {
7844    pub kind: String,
7845    pub this: Box<Expression>,
7846    pub expression: Box<Expression>,
7847    #[serde(default)]
7848    pub using: Option<Box<Expression>>,
7849}
7850
7851/// ProjectionDef
7852#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7853#[cfg_attr(feature = "bindings", derive(TS))]
7854pub struct ProjectionDef {
7855    pub this: Box<Expression>,
7856    pub expression: Box<Expression>,
7857}
7858
7859/// TableAlias
7860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7861#[cfg_attr(feature = "bindings", derive(TS))]
7862pub struct TableAlias {
7863    #[serde(default)]
7864    pub this: Option<Box<Expression>>,
7865    #[serde(default)]
7866    pub columns: Vec<Expression>,
7867}
7868
7869/// ByteString
7870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7871#[cfg_attr(feature = "bindings", derive(TS))]
7872pub struct ByteString {
7873    pub this: Box<Expression>,
7874    #[serde(default)]
7875    pub is_bytes: Option<Box<Expression>>,
7876}
7877
7878/// HexStringExpr - Hex string expression (not literal)
7879/// BigQuery: converts to FROM_HEX(this)
7880#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7881#[cfg_attr(feature = "bindings", derive(TS))]
7882pub struct HexStringExpr {
7883    pub this: Box<Expression>,
7884    #[serde(default)]
7885    pub is_integer: Option<bool>,
7886}
7887
7888/// UnicodeString
7889#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7890#[cfg_attr(feature = "bindings", derive(TS))]
7891pub struct UnicodeString {
7892    pub this: Box<Expression>,
7893    #[serde(default)]
7894    pub escape: Option<Box<Expression>>,
7895}
7896
7897/// AlterColumn
7898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7899#[cfg_attr(feature = "bindings", derive(TS))]
7900pub struct AlterColumn {
7901    pub this: Box<Expression>,
7902    #[serde(default)]
7903    pub dtype: Option<Box<Expression>>,
7904    #[serde(default)]
7905    pub collate: Option<Box<Expression>>,
7906    #[serde(default)]
7907    pub using: Option<Box<Expression>>,
7908    #[serde(default)]
7909    pub default: Option<Box<Expression>>,
7910    #[serde(default)]
7911    pub drop: Option<Box<Expression>>,
7912    #[serde(default)]
7913    pub comment: Option<Box<Expression>>,
7914    #[serde(default)]
7915    pub allow_null: Option<Box<Expression>>,
7916    #[serde(default)]
7917    pub visible: Option<Box<Expression>>,
7918    #[serde(default)]
7919    pub rename_to: Option<Box<Expression>>,
7920}
7921
7922/// AlterSortKey
7923#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7924#[cfg_attr(feature = "bindings", derive(TS))]
7925pub struct AlterSortKey {
7926    #[serde(default)]
7927    pub this: Option<Box<Expression>>,
7928    #[serde(default)]
7929    pub expressions: Vec<Expression>,
7930    #[serde(default)]
7931    pub compound: Option<Box<Expression>>,
7932}
7933
7934/// AlterSet
7935#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7936#[cfg_attr(feature = "bindings", derive(TS))]
7937pub struct AlterSet {
7938    #[serde(default)]
7939    pub expressions: Vec<Expression>,
7940    #[serde(default)]
7941    pub option: Option<Box<Expression>>,
7942    #[serde(default)]
7943    pub tablespace: Option<Box<Expression>>,
7944    #[serde(default)]
7945    pub access_method: Option<Box<Expression>>,
7946    #[serde(default)]
7947    pub file_format: Option<Box<Expression>>,
7948    #[serde(default)]
7949    pub copy_options: Option<Box<Expression>>,
7950    #[serde(default)]
7951    pub tag: Option<Box<Expression>>,
7952    #[serde(default)]
7953    pub location: Option<Box<Expression>>,
7954    #[serde(default)]
7955    pub serde: Option<Box<Expression>>,
7956}
7957
7958/// RenameColumn
7959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7960#[cfg_attr(feature = "bindings", derive(TS))]
7961pub struct RenameColumn {
7962    pub this: Box<Expression>,
7963    #[serde(default)]
7964    pub to: Option<Box<Expression>>,
7965    #[serde(default)]
7966    pub exists: bool,
7967}
7968
7969/// Comprehension
7970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7971#[cfg_attr(feature = "bindings", derive(TS))]
7972pub struct Comprehension {
7973    pub this: Box<Expression>,
7974    pub expression: Box<Expression>,
7975    #[serde(default)]
7976    pub position: Option<Box<Expression>>,
7977    #[serde(default)]
7978    pub iterator: Option<Box<Expression>>,
7979    #[serde(default)]
7980    pub condition: Option<Box<Expression>>,
7981}
7982
7983/// MergeTreeTTLAction
7984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7985#[cfg_attr(feature = "bindings", derive(TS))]
7986pub struct MergeTreeTTLAction {
7987    pub this: Box<Expression>,
7988    #[serde(default)]
7989    pub delete: Option<Box<Expression>>,
7990    #[serde(default)]
7991    pub recompress: Option<Box<Expression>>,
7992    #[serde(default)]
7993    pub to_disk: Option<Box<Expression>>,
7994    #[serde(default)]
7995    pub to_volume: Option<Box<Expression>>,
7996}
7997
7998/// MergeTreeTTL
7999#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8000#[cfg_attr(feature = "bindings", derive(TS))]
8001pub struct MergeTreeTTL {
8002    #[serde(default)]
8003    pub expressions: Vec<Expression>,
8004    #[serde(default)]
8005    pub where_: Option<Box<Expression>>,
8006    #[serde(default)]
8007    pub group: Option<Box<Expression>>,
8008    #[serde(default)]
8009    pub aggregates: Option<Box<Expression>>,
8010}
8011
8012/// IndexConstraintOption
8013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8014#[cfg_attr(feature = "bindings", derive(TS))]
8015pub struct IndexConstraintOption {
8016    #[serde(default)]
8017    pub key_block_size: Option<Box<Expression>>,
8018    #[serde(default)]
8019    pub using: Option<Box<Expression>>,
8020    #[serde(default)]
8021    pub parser: Option<Box<Expression>>,
8022    #[serde(default)]
8023    pub comment: Option<Box<Expression>>,
8024    #[serde(default)]
8025    pub visible: Option<Box<Expression>>,
8026    #[serde(default)]
8027    pub engine_attr: Option<Box<Expression>>,
8028    #[serde(default)]
8029    pub secondary_engine_attr: Option<Box<Expression>>,
8030}
8031
8032/// PeriodForSystemTimeConstraint
8033#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8034#[cfg_attr(feature = "bindings", derive(TS))]
8035pub struct PeriodForSystemTimeConstraint {
8036    pub this: Box<Expression>,
8037    pub expression: Box<Expression>,
8038}
8039
8040/// CaseSpecificColumnConstraint
8041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8042#[cfg_attr(feature = "bindings", derive(TS))]
8043pub struct CaseSpecificColumnConstraint {
8044    #[serde(default)]
8045    pub not_: Option<Box<Expression>>,
8046}
8047
8048/// CharacterSetColumnConstraint
8049#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8050#[cfg_attr(feature = "bindings", derive(TS))]
8051pub struct CharacterSetColumnConstraint {
8052    pub this: Box<Expression>,
8053}
8054
8055/// CheckColumnConstraint
8056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8057#[cfg_attr(feature = "bindings", derive(TS))]
8058pub struct CheckColumnConstraint {
8059    pub this: Box<Expression>,
8060    #[serde(default)]
8061    pub enforced: Option<Box<Expression>>,
8062}
8063
8064/// CompressColumnConstraint
8065#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8066#[cfg_attr(feature = "bindings", derive(TS))]
8067pub struct CompressColumnConstraint {
8068    #[serde(default)]
8069    pub this: Option<Box<Expression>>,
8070}
8071
8072/// DateFormatColumnConstraint
8073#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8074#[cfg_attr(feature = "bindings", derive(TS))]
8075pub struct DateFormatColumnConstraint {
8076    pub this: Box<Expression>,
8077}
8078
8079/// EphemeralColumnConstraint
8080#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8081#[cfg_attr(feature = "bindings", derive(TS))]
8082pub struct EphemeralColumnConstraint {
8083    #[serde(default)]
8084    pub this: Option<Box<Expression>>,
8085}
8086
8087/// WithOperator
8088#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8089#[cfg_attr(feature = "bindings", derive(TS))]
8090pub struct WithOperator {
8091    pub this: Box<Expression>,
8092    pub op: String,
8093}
8094
8095/// GeneratedAsIdentityColumnConstraint
8096#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8097#[cfg_attr(feature = "bindings", derive(TS))]
8098pub struct GeneratedAsIdentityColumnConstraint {
8099    #[serde(default)]
8100    pub this: Option<Box<Expression>>,
8101    #[serde(default)]
8102    pub expression: Option<Box<Expression>>,
8103    #[serde(default)]
8104    pub on_null: Option<Box<Expression>>,
8105    #[serde(default)]
8106    pub start: Option<Box<Expression>>,
8107    #[serde(default)]
8108    pub increment: Option<Box<Expression>>,
8109    #[serde(default)]
8110    pub minvalue: Option<Box<Expression>>,
8111    #[serde(default)]
8112    pub maxvalue: Option<Box<Expression>>,
8113    #[serde(default)]
8114    pub cycle: Option<Box<Expression>>,
8115    #[serde(default)]
8116    pub order: Option<Box<Expression>>,
8117}
8118
8119/// AutoIncrementColumnConstraint - MySQL/TSQL auto-increment marker
8120/// TSQL: outputs "IDENTITY"
8121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8122#[cfg_attr(feature = "bindings", derive(TS))]
8123pub struct AutoIncrementColumnConstraint;
8124
8125/// CommentColumnConstraint - Column comment marker
8126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8127#[cfg_attr(feature = "bindings", derive(TS))]
8128pub struct CommentColumnConstraint;
8129
8130/// GeneratedAsRowColumnConstraint
8131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8132#[cfg_attr(feature = "bindings", derive(TS))]
8133pub struct GeneratedAsRowColumnConstraint {
8134    #[serde(default)]
8135    pub start: Option<Box<Expression>>,
8136    #[serde(default)]
8137    pub hidden: Option<Box<Expression>>,
8138}
8139
8140/// IndexColumnConstraint
8141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8142#[cfg_attr(feature = "bindings", derive(TS))]
8143pub struct IndexColumnConstraint {
8144    #[serde(default)]
8145    pub this: Option<Box<Expression>>,
8146    #[serde(default)]
8147    pub expressions: Vec<Expression>,
8148    #[serde(default)]
8149    pub kind: Option<String>,
8150    #[serde(default)]
8151    pub index_type: Option<Box<Expression>>,
8152    #[serde(default)]
8153    pub options: Vec<Expression>,
8154    #[serde(default)]
8155    pub expression: Option<Box<Expression>>,
8156    #[serde(default)]
8157    pub granularity: Option<Box<Expression>>,
8158}
8159
8160/// MaskingPolicyColumnConstraint
8161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8162#[cfg_attr(feature = "bindings", derive(TS))]
8163pub struct MaskingPolicyColumnConstraint {
8164    pub this: Box<Expression>,
8165    #[serde(default)]
8166    pub expressions: Vec<Expression>,
8167}
8168
8169/// NotNullColumnConstraint
8170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8171#[cfg_attr(feature = "bindings", derive(TS))]
8172pub struct NotNullColumnConstraint {
8173    #[serde(default)]
8174    pub allow_null: Option<Box<Expression>>,
8175}
8176
8177/// DefaultColumnConstraint - DEFAULT value for a column
8178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8179#[cfg_attr(feature = "bindings", derive(TS))]
8180pub struct DefaultColumnConstraint {
8181    pub this: Box<Expression>,
8182}
8183
8184/// PrimaryKeyColumnConstraint
8185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8186#[cfg_attr(feature = "bindings", derive(TS))]
8187pub struct PrimaryKeyColumnConstraint {
8188    #[serde(default)]
8189    pub desc: Option<Box<Expression>>,
8190    #[serde(default)]
8191    pub options: Vec<Expression>,
8192}
8193
8194/// UniqueColumnConstraint
8195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8196#[cfg_attr(feature = "bindings", derive(TS))]
8197pub struct UniqueColumnConstraint {
8198    #[serde(default)]
8199    pub this: Option<Box<Expression>>,
8200    #[serde(default)]
8201    pub index_type: Option<Box<Expression>>,
8202    #[serde(default)]
8203    pub on_conflict: Option<Box<Expression>>,
8204    #[serde(default)]
8205    pub nulls: Option<Box<Expression>>,
8206    #[serde(default)]
8207    pub options: Vec<Expression>,
8208}
8209
8210/// WatermarkColumnConstraint
8211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8212#[cfg_attr(feature = "bindings", derive(TS))]
8213pub struct WatermarkColumnConstraint {
8214    pub this: Box<Expression>,
8215    pub expression: Box<Expression>,
8216}
8217
8218/// ComputedColumnConstraint
8219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8220#[cfg_attr(feature = "bindings", derive(TS))]
8221pub struct ComputedColumnConstraint {
8222    pub this: Box<Expression>,
8223    #[serde(default)]
8224    pub persisted: Option<Box<Expression>>,
8225    #[serde(default)]
8226    pub not_null: Option<Box<Expression>>,
8227    #[serde(default)]
8228    pub data_type: Option<Box<Expression>>,
8229}
8230
8231/// InOutColumnConstraint
8232#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8233#[cfg_attr(feature = "bindings", derive(TS))]
8234pub struct InOutColumnConstraint {
8235    #[serde(default)]
8236    pub input_: Option<Box<Expression>>,
8237    #[serde(default)]
8238    pub output: Option<Box<Expression>>,
8239}
8240
8241/// PathColumnConstraint - PATH 'xpath' for XMLTABLE/JSON_TABLE columns
8242#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8243#[cfg_attr(feature = "bindings", derive(TS))]
8244pub struct PathColumnConstraint {
8245    pub this: Box<Expression>,
8246}
8247
8248/// Constraint
8249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8250#[cfg_attr(feature = "bindings", derive(TS))]
8251pub struct Constraint {
8252    pub this: Box<Expression>,
8253    #[serde(default)]
8254    pub expressions: Vec<Expression>,
8255}
8256
8257/// Export
8258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8259#[cfg_attr(feature = "bindings", derive(TS))]
8260pub struct Export {
8261    pub this: Box<Expression>,
8262    #[serde(default)]
8263    pub connection: Option<Box<Expression>>,
8264    #[serde(default)]
8265    pub options: Vec<Expression>,
8266}
8267
8268/// Filter
8269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8270#[cfg_attr(feature = "bindings", derive(TS))]
8271pub struct Filter {
8272    pub this: Box<Expression>,
8273    pub expression: Box<Expression>,
8274}
8275
8276/// Changes
8277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8278#[cfg_attr(feature = "bindings", derive(TS))]
8279pub struct Changes {
8280    #[serde(default)]
8281    pub information: Option<Box<Expression>>,
8282    #[serde(default)]
8283    pub at_before: Option<Box<Expression>>,
8284    #[serde(default)]
8285    pub end: Option<Box<Expression>>,
8286}
8287
8288/// Directory
8289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8290#[cfg_attr(feature = "bindings", derive(TS))]
8291pub struct Directory {
8292    pub this: Box<Expression>,
8293    #[serde(default)]
8294    pub local: Option<Box<Expression>>,
8295    #[serde(default)]
8296    pub row_format: Option<Box<Expression>>,
8297}
8298
8299/// ForeignKey
8300#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8301#[cfg_attr(feature = "bindings", derive(TS))]
8302pub struct ForeignKey {
8303    #[serde(default)]
8304    pub expressions: Vec<Expression>,
8305    #[serde(default)]
8306    pub reference: Option<Box<Expression>>,
8307    #[serde(default)]
8308    pub delete: Option<Box<Expression>>,
8309    #[serde(default)]
8310    pub update: Option<Box<Expression>>,
8311    #[serde(default)]
8312    pub options: Vec<Expression>,
8313}
8314
8315/// ColumnPrefix
8316#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8317#[cfg_attr(feature = "bindings", derive(TS))]
8318pub struct ColumnPrefix {
8319    pub this: Box<Expression>,
8320    pub expression: Box<Expression>,
8321}
8322
8323/// PrimaryKey
8324#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8325#[cfg_attr(feature = "bindings", derive(TS))]
8326pub struct PrimaryKey {
8327    #[serde(default)]
8328    pub this: Option<Box<Expression>>,
8329    #[serde(default)]
8330    pub expressions: Vec<Expression>,
8331    #[serde(default)]
8332    pub options: Vec<Expression>,
8333    #[serde(default)]
8334    pub include: Option<Box<Expression>>,
8335}
8336
8337/// Into
8338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8339#[cfg_attr(feature = "bindings", derive(TS))]
8340pub struct IntoClause {
8341    #[serde(default)]
8342    pub this: Option<Box<Expression>>,
8343    #[serde(default)]
8344    pub temporary: bool,
8345    #[serde(default)]
8346    pub unlogged: Option<Box<Expression>>,
8347    #[serde(default)]
8348    pub bulk_collect: Option<Box<Expression>>,
8349    #[serde(default)]
8350    pub expressions: Vec<Expression>,
8351}
8352
8353/// JoinHint
8354#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8355#[cfg_attr(feature = "bindings", derive(TS))]
8356pub struct JoinHint {
8357    pub this: Box<Expression>,
8358    #[serde(default)]
8359    pub expressions: Vec<Expression>,
8360}
8361
8362/// Opclass
8363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8364#[cfg_attr(feature = "bindings", derive(TS))]
8365pub struct Opclass {
8366    pub this: Box<Expression>,
8367    pub expression: Box<Expression>,
8368}
8369
8370/// Index
8371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8372#[cfg_attr(feature = "bindings", derive(TS))]
8373pub struct Index {
8374    #[serde(default)]
8375    pub this: Option<Box<Expression>>,
8376    #[serde(default)]
8377    pub table: Option<Box<Expression>>,
8378    #[serde(default)]
8379    pub unique: bool,
8380    #[serde(default)]
8381    pub primary: Option<Box<Expression>>,
8382    #[serde(default)]
8383    pub amp: Option<Box<Expression>>,
8384    #[serde(default)]
8385    pub params: Vec<Expression>,
8386}
8387
8388/// IndexParameters
8389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8390#[cfg_attr(feature = "bindings", derive(TS))]
8391pub struct IndexParameters {
8392    #[serde(default)]
8393    pub using: Option<Box<Expression>>,
8394    #[serde(default)]
8395    pub include: Option<Box<Expression>>,
8396    #[serde(default)]
8397    pub columns: Vec<Expression>,
8398    #[serde(default)]
8399    pub with_storage: Option<Box<Expression>>,
8400    #[serde(default)]
8401    pub partition_by: Option<Box<Expression>>,
8402    #[serde(default)]
8403    pub tablespace: Option<Box<Expression>>,
8404    #[serde(default)]
8405    pub where_: Option<Box<Expression>>,
8406    #[serde(default)]
8407    pub on: Option<Box<Expression>>,
8408}
8409
8410/// ConditionalInsert
8411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8412#[cfg_attr(feature = "bindings", derive(TS))]
8413pub struct ConditionalInsert {
8414    pub this: Box<Expression>,
8415    #[serde(default)]
8416    pub expression: Option<Box<Expression>>,
8417    #[serde(default)]
8418    pub else_: Option<Box<Expression>>,
8419}
8420
8421/// MultitableInserts
8422#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8423#[cfg_attr(feature = "bindings", derive(TS))]
8424pub struct MultitableInserts {
8425    #[serde(default)]
8426    pub expressions: Vec<Expression>,
8427    pub kind: String,
8428    #[serde(default)]
8429    pub source: Option<Box<Expression>>,
8430    /// Leading comments before the statement
8431    #[serde(default)]
8432    pub leading_comments: Vec<String>,
8433}
8434
8435/// OnConflict
8436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8437#[cfg_attr(feature = "bindings", derive(TS))]
8438pub struct OnConflict {
8439    #[serde(default)]
8440    pub duplicate: Option<Box<Expression>>,
8441    #[serde(default)]
8442    pub expressions: Vec<Expression>,
8443    #[serde(default)]
8444    pub action: Option<Box<Expression>>,
8445    #[serde(default)]
8446    pub conflict_keys: Option<Box<Expression>>,
8447    #[serde(default)]
8448    pub index_predicate: Option<Box<Expression>>,
8449    #[serde(default)]
8450    pub constraint: Option<Box<Expression>>,
8451    #[serde(default)]
8452    pub where_: Option<Box<Expression>>,
8453}
8454
8455/// OnCondition
8456#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8457#[cfg_attr(feature = "bindings", derive(TS))]
8458pub struct OnCondition {
8459    #[serde(default)]
8460    pub error: Option<Box<Expression>>,
8461    #[serde(default)]
8462    pub empty: Option<Box<Expression>>,
8463    #[serde(default)]
8464    pub null: Option<Box<Expression>>,
8465}
8466
8467/// Returning
8468#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8469#[cfg_attr(feature = "bindings", derive(TS))]
8470pub struct Returning {
8471    #[serde(default)]
8472    pub expressions: Vec<Expression>,
8473    #[serde(default)]
8474    pub into: Option<Box<Expression>>,
8475}
8476
8477/// Introducer
8478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8479#[cfg_attr(feature = "bindings", derive(TS))]
8480pub struct Introducer {
8481    pub this: Box<Expression>,
8482    pub expression: Box<Expression>,
8483}
8484
8485/// PartitionRange
8486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8487#[cfg_attr(feature = "bindings", derive(TS))]
8488pub struct PartitionRange {
8489    pub this: Box<Expression>,
8490    #[serde(default)]
8491    pub expression: Option<Box<Expression>>,
8492    #[serde(default)]
8493    pub expressions: Vec<Expression>,
8494}
8495
8496/// Group
8497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8498#[cfg_attr(feature = "bindings", derive(TS))]
8499pub struct Group {
8500    #[serde(default)]
8501    pub expressions: Vec<Expression>,
8502    #[serde(default)]
8503    pub grouping_sets: Option<Box<Expression>>,
8504    #[serde(default)]
8505    pub cube: Option<Box<Expression>>,
8506    #[serde(default)]
8507    pub rollup: Option<Box<Expression>>,
8508    #[serde(default)]
8509    pub totals: Option<Box<Expression>>,
8510    /// GROUP BY modifier: Some(true) = ALL, Some(false) = DISTINCT, None = no modifier
8511    #[serde(default)]
8512    pub all: Option<bool>,
8513}
8514
8515/// Cube
8516#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8517#[cfg_attr(feature = "bindings", derive(TS))]
8518pub struct Cube {
8519    #[serde(default)]
8520    pub expressions: Vec<Expression>,
8521}
8522
8523/// Rollup
8524#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8525#[cfg_attr(feature = "bindings", derive(TS))]
8526pub struct Rollup {
8527    #[serde(default)]
8528    pub expressions: Vec<Expression>,
8529}
8530
8531/// GroupingSets
8532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8533#[cfg_attr(feature = "bindings", derive(TS))]
8534pub struct GroupingSets {
8535    #[serde(default)]
8536    pub expressions: Vec<Expression>,
8537}
8538
8539/// LimitOptions
8540#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8541#[cfg_attr(feature = "bindings", derive(TS))]
8542pub struct LimitOptions {
8543    #[serde(default)]
8544    pub percent: Option<Box<Expression>>,
8545    #[serde(default)]
8546    pub rows: Option<Box<Expression>>,
8547    #[serde(default)]
8548    pub with_ties: Option<Box<Expression>>,
8549}
8550
8551/// Lateral
8552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8553#[cfg_attr(feature = "bindings", derive(TS))]
8554pub struct Lateral {
8555    pub this: Box<Expression>,
8556    #[serde(default)]
8557    pub view: Option<Box<Expression>>,
8558    #[serde(default)]
8559    pub outer: Option<Box<Expression>>,
8560    #[serde(default)]
8561    pub alias: Option<String>,
8562    /// Whether the alias was originally quoted (backtick/double-quote)
8563    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
8564    pub alias_quoted: bool,
8565    #[serde(default)]
8566    pub cross_apply: Option<Box<Expression>>,
8567    #[serde(default)]
8568    pub ordinality: Option<Box<Expression>>,
8569    /// Column aliases for the lateral expression (e.g., LATERAL func() AS alias(col1, col2))
8570    #[serde(default, skip_serializing_if = "Vec::is_empty")]
8571    pub column_aliases: Vec<String>,
8572}
8573
8574/// TableFromRows
8575#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8576#[cfg_attr(feature = "bindings", derive(TS))]
8577pub struct TableFromRows {
8578    pub this: Box<Expression>,
8579    #[serde(default)]
8580    pub alias: Option<String>,
8581    #[serde(default)]
8582    pub joins: Vec<Expression>,
8583    #[serde(default)]
8584    pub pivots: Option<Box<Expression>>,
8585    #[serde(default)]
8586    pub sample: Option<Box<Expression>>,
8587}
8588
8589/// RowsFrom - PostgreSQL ROWS FROM (func1(args) AS alias1(...), func2(args) AS alias2(...)) syntax
8590/// Used for set-returning functions with typed column definitions
8591#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8592#[cfg_attr(feature = "bindings", derive(TS))]
8593pub struct RowsFrom {
8594    /// List of function expressions, each potentially with an alias and typed columns
8595    pub expressions: Vec<Expression>,
8596    /// WITH ORDINALITY modifier
8597    #[serde(default)]
8598    pub ordinality: bool,
8599    /// Optional outer alias: ROWS FROM (...) AS alias(col1 type1, col2 type2)
8600    #[serde(default)]
8601    pub alias: Option<Box<Expression>>,
8602}
8603
8604/// WithFill
8605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8606#[cfg_attr(feature = "bindings", derive(TS))]
8607pub struct WithFill {
8608    #[serde(default)]
8609    pub from_: Option<Box<Expression>>,
8610    #[serde(default)]
8611    pub to: Option<Box<Expression>>,
8612    #[serde(default)]
8613    pub step: Option<Box<Expression>>,
8614    #[serde(default)]
8615    pub staleness: Option<Box<Expression>>,
8616    #[serde(default)]
8617    pub interpolate: Option<Box<Expression>>,
8618}
8619
8620/// Property
8621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8622#[cfg_attr(feature = "bindings", derive(TS))]
8623pub struct Property {
8624    pub this: Box<Expression>,
8625    #[serde(default)]
8626    pub value: Option<Box<Expression>>,
8627}
8628
8629/// GrantPrivilege
8630#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8631#[cfg_attr(feature = "bindings", derive(TS))]
8632pub struct GrantPrivilege {
8633    pub this: Box<Expression>,
8634    #[serde(default)]
8635    pub expressions: Vec<Expression>,
8636}
8637
8638/// AllowedValuesProperty
8639#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8640#[cfg_attr(feature = "bindings", derive(TS))]
8641pub struct AllowedValuesProperty {
8642    #[serde(default)]
8643    pub expressions: Vec<Expression>,
8644}
8645
8646/// AlgorithmProperty
8647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8648#[cfg_attr(feature = "bindings", derive(TS))]
8649pub struct AlgorithmProperty {
8650    pub this: Box<Expression>,
8651}
8652
8653/// AutoIncrementProperty
8654#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8655#[cfg_attr(feature = "bindings", derive(TS))]
8656pub struct AutoIncrementProperty {
8657    pub this: Box<Expression>,
8658}
8659
8660/// AutoRefreshProperty
8661#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8662#[cfg_attr(feature = "bindings", derive(TS))]
8663pub struct AutoRefreshProperty {
8664    pub this: Box<Expression>,
8665}
8666
8667/// BackupProperty
8668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8669#[cfg_attr(feature = "bindings", derive(TS))]
8670pub struct BackupProperty {
8671    pub this: Box<Expression>,
8672}
8673
8674/// BuildProperty
8675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8676#[cfg_attr(feature = "bindings", derive(TS))]
8677pub struct BuildProperty {
8678    pub this: Box<Expression>,
8679}
8680
8681/// BlockCompressionProperty
8682#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8683#[cfg_attr(feature = "bindings", derive(TS))]
8684pub struct BlockCompressionProperty {
8685    #[serde(default)]
8686    pub autotemp: Option<Box<Expression>>,
8687    #[serde(default)]
8688    pub always: Option<Box<Expression>>,
8689    #[serde(default)]
8690    pub default: Option<Box<Expression>>,
8691    #[serde(default)]
8692    pub manual: Option<Box<Expression>>,
8693    #[serde(default)]
8694    pub never: Option<Box<Expression>>,
8695}
8696
8697/// CharacterSetProperty
8698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8699#[cfg_attr(feature = "bindings", derive(TS))]
8700pub struct CharacterSetProperty {
8701    pub this: Box<Expression>,
8702    #[serde(default)]
8703    pub default: Option<Box<Expression>>,
8704}
8705
8706/// ChecksumProperty
8707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8708#[cfg_attr(feature = "bindings", derive(TS))]
8709pub struct ChecksumProperty {
8710    #[serde(default)]
8711    pub on: Option<Box<Expression>>,
8712    #[serde(default)]
8713    pub default: Option<Box<Expression>>,
8714}
8715
8716/// CollateProperty
8717#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8718#[cfg_attr(feature = "bindings", derive(TS))]
8719pub struct CollateProperty {
8720    pub this: Box<Expression>,
8721    #[serde(default)]
8722    pub default: Option<Box<Expression>>,
8723}
8724
8725/// DataBlocksizeProperty
8726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8727#[cfg_attr(feature = "bindings", derive(TS))]
8728pub struct DataBlocksizeProperty {
8729    #[serde(default)]
8730    pub size: Option<i64>,
8731    #[serde(default)]
8732    pub units: Option<Box<Expression>>,
8733    #[serde(default)]
8734    pub minimum: Option<Box<Expression>>,
8735    #[serde(default)]
8736    pub maximum: Option<Box<Expression>>,
8737    #[serde(default)]
8738    pub default: Option<Box<Expression>>,
8739}
8740
8741/// DataDeletionProperty
8742#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8743#[cfg_attr(feature = "bindings", derive(TS))]
8744pub struct DataDeletionProperty {
8745    pub on: Box<Expression>,
8746    #[serde(default)]
8747    pub filter_column: Option<Box<Expression>>,
8748    #[serde(default)]
8749    pub retention_period: Option<Box<Expression>>,
8750}
8751
8752/// DefinerProperty
8753#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8754#[cfg_attr(feature = "bindings", derive(TS))]
8755pub struct DefinerProperty {
8756    pub this: Box<Expression>,
8757}
8758
8759/// DistKeyProperty
8760#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8761#[cfg_attr(feature = "bindings", derive(TS))]
8762pub struct DistKeyProperty {
8763    pub this: Box<Expression>,
8764}
8765
8766/// DistributedByProperty
8767#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8768#[cfg_attr(feature = "bindings", derive(TS))]
8769pub struct DistributedByProperty {
8770    #[serde(default)]
8771    pub expressions: Vec<Expression>,
8772    pub kind: String,
8773    #[serde(default)]
8774    pub buckets: Option<Box<Expression>>,
8775    #[serde(default)]
8776    pub order: Option<Box<Expression>>,
8777}
8778
8779/// DistStyleProperty
8780#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8781#[cfg_attr(feature = "bindings", derive(TS))]
8782pub struct DistStyleProperty {
8783    pub this: Box<Expression>,
8784}
8785
8786/// DuplicateKeyProperty
8787#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8788#[cfg_attr(feature = "bindings", derive(TS))]
8789pub struct DuplicateKeyProperty {
8790    #[serde(default)]
8791    pub expressions: Vec<Expression>,
8792}
8793
8794/// EngineProperty
8795#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8796#[cfg_attr(feature = "bindings", derive(TS))]
8797pub struct EngineProperty {
8798    pub this: Box<Expression>,
8799}
8800
8801/// ToTableProperty
8802#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8803#[cfg_attr(feature = "bindings", derive(TS))]
8804pub struct ToTableProperty {
8805    pub this: Box<Expression>,
8806}
8807
8808/// ExecuteAsProperty
8809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8810#[cfg_attr(feature = "bindings", derive(TS))]
8811pub struct ExecuteAsProperty {
8812    pub this: Box<Expression>,
8813}
8814
8815/// ExternalProperty
8816#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8817#[cfg_attr(feature = "bindings", derive(TS))]
8818pub struct ExternalProperty {
8819    #[serde(default)]
8820    pub this: Option<Box<Expression>>,
8821}
8822
8823/// FallbackProperty
8824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8825#[cfg_attr(feature = "bindings", derive(TS))]
8826pub struct FallbackProperty {
8827    #[serde(default)]
8828    pub no: Option<Box<Expression>>,
8829    #[serde(default)]
8830    pub protection: Option<Box<Expression>>,
8831}
8832
8833/// FileFormatProperty
8834#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8835#[cfg_attr(feature = "bindings", derive(TS))]
8836pub struct FileFormatProperty {
8837    #[serde(default)]
8838    pub this: Option<Box<Expression>>,
8839    #[serde(default)]
8840    pub expressions: Vec<Expression>,
8841    #[serde(default)]
8842    pub hive_format: Option<Box<Expression>>,
8843}
8844
8845/// CredentialsProperty
8846#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8847#[cfg_attr(feature = "bindings", derive(TS))]
8848pub struct CredentialsProperty {
8849    #[serde(default)]
8850    pub expressions: Vec<Expression>,
8851}
8852
8853/// FreespaceProperty
8854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8855#[cfg_attr(feature = "bindings", derive(TS))]
8856pub struct FreespaceProperty {
8857    pub this: Box<Expression>,
8858    #[serde(default)]
8859    pub percent: Option<Box<Expression>>,
8860}
8861
8862/// InheritsProperty
8863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8864#[cfg_attr(feature = "bindings", derive(TS))]
8865pub struct InheritsProperty {
8866    #[serde(default)]
8867    pub expressions: Vec<Expression>,
8868}
8869
8870/// InputModelProperty
8871#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8872#[cfg_attr(feature = "bindings", derive(TS))]
8873pub struct InputModelProperty {
8874    pub this: Box<Expression>,
8875}
8876
8877/// OutputModelProperty
8878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8879#[cfg_attr(feature = "bindings", derive(TS))]
8880pub struct OutputModelProperty {
8881    pub this: Box<Expression>,
8882}
8883
8884/// IsolatedLoadingProperty
8885#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8886#[cfg_attr(feature = "bindings", derive(TS))]
8887pub struct IsolatedLoadingProperty {
8888    #[serde(default)]
8889    pub no: Option<Box<Expression>>,
8890    #[serde(default)]
8891    pub concurrent: Option<Box<Expression>>,
8892    #[serde(default)]
8893    pub target: Option<Box<Expression>>,
8894}
8895
8896/// JournalProperty
8897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8898#[cfg_attr(feature = "bindings", derive(TS))]
8899pub struct JournalProperty {
8900    #[serde(default)]
8901    pub no: Option<Box<Expression>>,
8902    #[serde(default)]
8903    pub dual: Option<Box<Expression>>,
8904    #[serde(default)]
8905    pub before: Option<Box<Expression>>,
8906    #[serde(default)]
8907    pub local: Option<Box<Expression>>,
8908    #[serde(default)]
8909    pub after: Option<Box<Expression>>,
8910}
8911
8912/// LanguageProperty
8913#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8914#[cfg_attr(feature = "bindings", derive(TS))]
8915pub struct LanguageProperty {
8916    pub this: Box<Expression>,
8917}
8918
8919/// EnviromentProperty
8920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8921#[cfg_attr(feature = "bindings", derive(TS))]
8922pub struct EnviromentProperty {
8923    #[serde(default)]
8924    pub expressions: Vec<Expression>,
8925}
8926
8927/// ClusteredByProperty
8928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8929#[cfg_attr(feature = "bindings", derive(TS))]
8930pub struct ClusteredByProperty {
8931    #[serde(default)]
8932    pub expressions: Vec<Expression>,
8933    #[serde(default)]
8934    pub sorted_by: Option<Box<Expression>>,
8935    #[serde(default)]
8936    pub buckets: Option<Box<Expression>>,
8937}
8938
8939/// DictProperty
8940#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8941#[cfg_attr(feature = "bindings", derive(TS))]
8942pub struct DictProperty {
8943    pub this: Box<Expression>,
8944    pub kind: String,
8945    #[serde(default)]
8946    pub settings: Option<Box<Expression>>,
8947}
8948
8949/// DictRange
8950#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8951#[cfg_attr(feature = "bindings", derive(TS))]
8952pub struct DictRange {
8953    pub this: Box<Expression>,
8954    #[serde(default)]
8955    pub min: Option<Box<Expression>>,
8956    #[serde(default)]
8957    pub max: Option<Box<Expression>>,
8958}
8959
8960/// OnCluster
8961#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8962#[cfg_attr(feature = "bindings", derive(TS))]
8963pub struct OnCluster {
8964    pub this: Box<Expression>,
8965}
8966
8967/// LikeProperty
8968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8969#[cfg_attr(feature = "bindings", derive(TS))]
8970pub struct LikeProperty {
8971    pub this: Box<Expression>,
8972    #[serde(default)]
8973    pub expressions: Vec<Expression>,
8974}
8975
8976/// LocationProperty
8977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8978#[cfg_attr(feature = "bindings", derive(TS))]
8979pub struct LocationProperty {
8980    pub this: Box<Expression>,
8981}
8982
8983/// LockProperty
8984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8985#[cfg_attr(feature = "bindings", derive(TS))]
8986pub struct LockProperty {
8987    pub this: Box<Expression>,
8988}
8989
8990/// LockingProperty
8991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8992#[cfg_attr(feature = "bindings", derive(TS))]
8993pub struct LockingProperty {
8994    #[serde(default)]
8995    pub this: Option<Box<Expression>>,
8996    pub kind: String,
8997    #[serde(default)]
8998    pub for_or_in: Option<Box<Expression>>,
8999    #[serde(default)]
9000    pub lock_type: Option<Box<Expression>>,
9001    #[serde(default)]
9002    pub override_: Option<Box<Expression>>,
9003}
9004
9005/// LogProperty
9006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9007#[cfg_attr(feature = "bindings", derive(TS))]
9008pub struct LogProperty {
9009    #[serde(default)]
9010    pub no: Option<Box<Expression>>,
9011}
9012
9013/// MaterializedProperty
9014#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9015#[cfg_attr(feature = "bindings", derive(TS))]
9016pub struct MaterializedProperty {
9017    #[serde(default)]
9018    pub this: Option<Box<Expression>>,
9019}
9020
9021/// MergeBlockRatioProperty
9022#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9023#[cfg_attr(feature = "bindings", derive(TS))]
9024pub struct MergeBlockRatioProperty {
9025    #[serde(default)]
9026    pub this: Option<Box<Expression>>,
9027    #[serde(default)]
9028    pub no: Option<Box<Expression>>,
9029    #[serde(default)]
9030    pub default: Option<Box<Expression>>,
9031    #[serde(default)]
9032    pub percent: Option<Box<Expression>>,
9033}
9034
9035/// OnProperty
9036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9037#[cfg_attr(feature = "bindings", derive(TS))]
9038pub struct OnProperty {
9039    pub this: Box<Expression>,
9040}
9041
9042/// OnCommitProperty
9043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9044#[cfg_attr(feature = "bindings", derive(TS))]
9045pub struct OnCommitProperty {
9046    #[serde(default)]
9047    pub delete: Option<Box<Expression>>,
9048}
9049
9050/// PartitionedByProperty
9051#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9052#[cfg_attr(feature = "bindings", derive(TS))]
9053pub struct PartitionedByProperty {
9054    pub this: Box<Expression>,
9055}
9056
9057/// PartitionedByBucket
9058#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9059#[cfg_attr(feature = "bindings", derive(TS))]
9060pub struct PartitionedByBucket {
9061    pub this: Box<Expression>,
9062    pub expression: Box<Expression>,
9063}
9064
9065/// PartitionByTruncate
9066#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9067#[cfg_attr(feature = "bindings", derive(TS))]
9068pub struct PartitionByTruncate {
9069    pub this: Box<Expression>,
9070    pub expression: Box<Expression>,
9071}
9072
9073/// PartitionByRangeProperty
9074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9075#[cfg_attr(feature = "bindings", derive(TS))]
9076pub struct PartitionByRangeProperty {
9077    #[serde(default)]
9078    pub partition_expressions: Option<Box<Expression>>,
9079    #[serde(default)]
9080    pub create_expressions: Option<Box<Expression>>,
9081}
9082
9083/// PartitionByRangePropertyDynamic
9084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9085#[cfg_attr(feature = "bindings", derive(TS))]
9086pub struct PartitionByRangePropertyDynamic {
9087    #[serde(default)]
9088    pub this: Option<Box<Expression>>,
9089    #[serde(default)]
9090    pub start: Option<Box<Expression>>,
9091    /// Use START/END/EVERY keywords (StarRocks) instead of FROM/TO/INTERVAL (Doris)
9092    #[serde(default)]
9093    pub use_start_end: bool,
9094    #[serde(default)]
9095    pub end: Option<Box<Expression>>,
9096    #[serde(default)]
9097    pub every: Option<Box<Expression>>,
9098}
9099
9100/// PartitionByListProperty
9101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9102#[cfg_attr(feature = "bindings", derive(TS))]
9103pub struct PartitionByListProperty {
9104    #[serde(default)]
9105    pub partition_expressions: Option<Box<Expression>>,
9106    #[serde(default)]
9107    pub create_expressions: Option<Box<Expression>>,
9108}
9109
9110/// PartitionList
9111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9112#[cfg_attr(feature = "bindings", derive(TS))]
9113pub struct PartitionList {
9114    pub this: Box<Expression>,
9115    #[serde(default)]
9116    pub expressions: Vec<Expression>,
9117}
9118
9119/// Partition - represents PARTITION/SUBPARTITION clause
9120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9121#[cfg_attr(feature = "bindings", derive(TS))]
9122pub struct Partition {
9123    pub expressions: Vec<Expression>,
9124    #[serde(default)]
9125    pub subpartition: bool,
9126}
9127
9128/// RefreshTriggerProperty - Doris REFRESH clause for materialized views
9129/// e.g., REFRESH COMPLETE ON MANUAL, REFRESH AUTO ON SCHEDULE EVERY 5 MINUTE
9130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9131#[cfg_attr(feature = "bindings", derive(TS))]
9132pub struct RefreshTriggerProperty {
9133    /// Method: COMPLETE or AUTO
9134    pub method: String,
9135    /// Trigger kind: MANUAL, COMMIT, or SCHEDULE
9136    #[serde(default)]
9137    pub kind: Option<String>,
9138    /// For SCHEDULE: EVERY n (the number)
9139    #[serde(default)]
9140    pub every: Option<Box<Expression>>,
9141    /// For SCHEDULE: the time unit (MINUTE, HOUR, DAY, etc.)
9142    #[serde(default)]
9143    pub unit: Option<String>,
9144    /// For SCHEDULE: STARTS 'datetime'
9145    #[serde(default)]
9146    pub starts: Option<Box<Expression>>,
9147}
9148
9149/// UniqueKeyProperty
9150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9151#[cfg_attr(feature = "bindings", derive(TS))]
9152pub struct UniqueKeyProperty {
9153    #[serde(default)]
9154    pub expressions: Vec<Expression>,
9155}
9156
9157/// RollupProperty - StarRocks ROLLUP (index_name(col1, col2), ...)
9158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9159#[cfg_attr(feature = "bindings", derive(TS))]
9160pub struct RollupProperty {
9161    pub expressions: Vec<RollupIndex>,
9162}
9163
9164/// RollupIndex - A single rollup index: name(col1, col2)
9165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9166#[cfg_attr(feature = "bindings", derive(TS))]
9167pub struct RollupIndex {
9168    pub name: Identifier,
9169    pub expressions: Vec<Identifier>,
9170}
9171
9172/// PartitionBoundSpec
9173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9174#[cfg_attr(feature = "bindings", derive(TS))]
9175pub struct PartitionBoundSpec {
9176    #[serde(default)]
9177    pub this: Option<Box<Expression>>,
9178    #[serde(default)]
9179    pub expression: Option<Box<Expression>>,
9180    #[serde(default)]
9181    pub from_expressions: Option<Box<Expression>>,
9182    #[serde(default)]
9183    pub to_expressions: Option<Box<Expression>>,
9184}
9185
9186/// PartitionedOfProperty
9187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9188#[cfg_attr(feature = "bindings", derive(TS))]
9189pub struct PartitionedOfProperty {
9190    pub this: Box<Expression>,
9191    pub expression: Box<Expression>,
9192}
9193
9194/// RemoteWithConnectionModelProperty
9195#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9196#[cfg_attr(feature = "bindings", derive(TS))]
9197pub struct RemoteWithConnectionModelProperty {
9198    pub this: Box<Expression>,
9199}
9200
9201/// ReturnsProperty
9202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9203#[cfg_attr(feature = "bindings", derive(TS))]
9204pub struct ReturnsProperty {
9205    #[serde(default)]
9206    pub this: Option<Box<Expression>>,
9207    #[serde(default)]
9208    pub is_table: Option<Box<Expression>>,
9209    #[serde(default)]
9210    pub table: Option<Box<Expression>>,
9211    #[serde(default)]
9212    pub null: Option<Box<Expression>>,
9213}
9214
9215/// RowFormatProperty
9216#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9217#[cfg_attr(feature = "bindings", derive(TS))]
9218pub struct RowFormatProperty {
9219    pub this: Box<Expression>,
9220}
9221
9222/// RowFormatDelimitedProperty
9223#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9224#[cfg_attr(feature = "bindings", derive(TS))]
9225pub struct RowFormatDelimitedProperty {
9226    #[serde(default)]
9227    pub fields: Option<Box<Expression>>,
9228    #[serde(default)]
9229    pub escaped: Option<Box<Expression>>,
9230    #[serde(default)]
9231    pub collection_items: Option<Box<Expression>>,
9232    #[serde(default)]
9233    pub map_keys: Option<Box<Expression>>,
9234    #[serde(default)]
9235    pub lines: Option<Box<Expression>>,
9236    #[serde(default)]
9237    pub null: Option<Box<Expression>>,
9238    #[serde(default)]
9239    pub serde: Option<Box<Expression>>,
9240}
9241
9242/// RowFormatSerdeProperty
9243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9244#[cfg_attr(feature = "bindings", derive(TS))]
9245pub struct RowFormatSerdeProperty {
9246    pub this: Box<Expression>,
9247    #[serde(default)]
9248    pub serde_properties: Option<Box<Expression>>,
9249}
9250
9251/// QueryTransform
9252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9253#[cfg_attr(feature = "bindings", derive(TS))]
9254pub struct QueryTransform {
9255    #[serde(default)]
9256    pub expressions: Vec<Expression>,
9257    #[serde(default)]
9258    pub command_script: Option<Box<Expression>>,
9259    #[serde(default)]
9260    pub schema: Option<Box<Expression>>,
9261    #[serde(default)]
9262    pub row_format_before: Option<Box<Expression>>,
9263    #[serde(default)]
9264    pub record_writer: Option<Box<Expression>>,
9265    #[serde(default)]
9266    pub row_format_after: Option<Box<Expression>>,
9267    #[serde(default)]
9268    pub record_reader: Option<Box<Expression>>,
9269}
9270
9271/// SampleProperty
9272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9273#[cfg_attr(feature = "bindings", derive(TS))]
9274pub struct SampleProperty {
9275    pub this: Box<Expression>,
9276}
9277
9278/// SecurityProperty
9279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9280#[cfg_attr(feature = "bindings", derive(TS))]
9281pub struct SecurityProperty {
9282    pub this: Box<Expression>,
9283}
9284
9285/// SchemaCommentProperty
9286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9287#[cfg_attr(feature = "bindings", derive(TS))]
9288pub struct SchemaCommentProperty {
9289    pub this: Box<Expression>,
9290}
9291
9292/// SemanticView
9293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9294#[cfg_attr(feature = "bindings", derive(TS))]
9295pub struct SemanticView {
9296    pub this: Box<Expression>,
9297    #[serde(default)]
9298    pub metrics: Option<Box<Expression>>,
9299    #[serde(default)]
9300    pub dimensions: Option<Box<Expression>>,
9301    #[serde(default)]
9302    pub facts: Option<Box<Expression>>,
9303    #[serde(default)]
9304    pub where_: Option<Box<Expression>>,
9305}
9306
9307/// SerdeProperties
9308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9309#[cfg_attr(feature = "bindings", derive(TS))]
9310pub struct SerdeProperties {
9311    #[serde(default)]
9312    pub expressions: Vec<Expression>,
9313    #[serde(default)]
9314    pub with_: Option<Box<Expression>>,
9315}
9316
9317/// SetProperty
9318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9319#[cfg_attr(feature = "bindings", derive(TS))]
9320pub struct SetProperty {
9321    #[serde(default)]
9322    pub multi: Option<Box<Expression>>,
9323}
9324
9325/// SharingProperty
9326#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9327#[cfg_attr(feature = "bindings", derive(TS))]
9328pub struct SharingProperty {
9329    #[serde(default)]
9330    pub this: Option<Box<Expression>>,
9331}
9332
9333/// SetConfigProperty
9334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9335#[cfg_attr(feature = "bindings", derive(TS))]
9336pub struct SetConfigProperty {
9337    pub this: Box<Expression>,
9338}
9339
9340/// SettingsProperty
9341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9342#[cfg_attr(feature = "bindings", derive(TS))]
9343pub struct SettingsProperty {
9344    #[serde(default)]
9345    pub expressions: Vec<Expression>,
9346}
9347
9348/// SortKeyProperty
9349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9350#[cfg_attr(feature = "bindings", derive(TS))]
9351pub struct SortKeyProperty {
9352    pub this: Box<Expression>,
9353    #[serde(default)]
9354    pub compound: Option<Box<Expression>>,
9355}
9356
9357/// SqlReadWriteProperty
9358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9359#[cfg_attr(feature = "bindings", derive(TS))]
9360pub struct SqlReadWriteProperty {
9361    pub this: Box<Expression>,
9362}
9363
9364/// SqlSecurityProperty
9365#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9366#[cfg_attr(feature = "bindings", derive(TS))]
9367pub struct SqlSecurityProperty {
9368    pub this: Box<Expression>,
9369}
9370
9371/// StabilityProperty
9372#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9373#[cfg_attr(feature = "bindings", derive(TS))]
9374pub struct StabilityProperty {
9375    pub this: Box<Expression>,
9376}
9377
9378/// StorageHandlerProperty
9379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9380#[cfg_attr(feature = "bindings", derive(TS))]
9381pub struct StorageHandlerProperty {
9382    pub this: Box<Expression>,
9383}
9384
9385/// TemporaryProperty
9386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9387#[cfg_attr(feature = "bindings", derive(TS))]
9388pub struct TemporaryProperty {
9389    #[serde(default)]
9390    pub this: Option<Box<Expression>>,
9391}
9392
9393/// Tags
9394#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9395#[cfg_attr(feature = "bindings", derive(TS))]
9396pub struct Tags {
9397    #[serde(default)]
9398    pub expressions: Vec<Expression>,
9399}
9400
9401/// TransformModelProperty
9402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9403#[cfg_attr(feature = "bindings", derive(TS))]
9404pub struct TransformModelProperty {
9405    #[serde(default)]
9406    pub expressions: Vec<Expression>,
9407}
9408
9409/// TransientProperty
9410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9411#[cfg_attr(feature = "bindings", derive(TS))]
9412pub struct TransientProperty {
9413    #[serde(default)]
9414    pub this: Option<Box<Expression>>,
9415}
9416
9417/// UsingTemplateProperty
9418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9419#[cfg_attr(feature = "bindings", derive(TS))]
9420pub struct UsingTemplateProperty {
9421    pub this: Box<Expression>,
9422}
9423
9424/// ViewAttributeProperty
9425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9426#[cfg_attr(feature = "bindings", derive(TS))]
9427pub struct ViewAttributeProperty {
9428    pub this: Box<Expression>,
9429}
9430
9431/// VolatileProperty
9432#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9433#[cfg_attr(feature = "bindings", derive(TS))]
9434pub struct VolatileProperty {
9435    #[serde(default)]
9436    pub this: Option<Box<Expression>>,
9437}
9438
9439/// WithDataProperty
9440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9441#[cfg_attr(feature = "bindings", derive(TS))]
9442pub struct WithDataProperty {
9443    #[serde(default)]
9444    pub no: Option<Box<Expression>>,
9445    #[serde(default)]
9446    pub statistics: Option<Box<Expression>>,
9447}
9448
9449/// WithJournalTableProperty
9450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9451#[cfg_attr(feature = "bindings", derive(TS))]
9452pub struct WithJournalTableProperty {
9453    pub this: Box<Expression>,
9454}
9455
9456/// WithSchemaBindingProperty
9457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9458#[cfg_attr(feature = "bindings", derive(TS))]
9459pub struct WithSchemaBindingProperty {
9460    pub this: Box<Expression>,
9461}
9462
9463/// WithSystemVersioningProperty
9464#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9465#[cfg_attr(feature = "bindings", derive(TS))]
9466pub struct WithSystemVersioningProperty {
9467    #[serde(default)]
9468    pub on: Option<Box<Expression>>,
9469    #[serde(default)]
9470    pub this: Option<Box<Expression>>,
9471    #[serde(default)]
9472    pub data_consistency: Option<Box<Expression>>,
9473    #[serde(default)]
9474    pub retention_period: Option<Box<Expression>>,
9475    #[serde(default)]
9476    pub with_: Option<Box<Expression>>,
9477}
9478
9479/// WithProcedureOptions
9480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9481#[cfg_attr(feature = "bindings", derive(TS))]
9482pub struct WithProcedureOptions {
9483    #[serde(default)]
9484    pub expressions: Vec<Expression>,
9485}
9486
9487/// EncodeProperty
9488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9489#[cfg_attr(feature = "bindings", derive(TS))]
9490pub struct EncodeProperty {
9491    pub this: Box<Expression>,
9492    #[serde(default)]
9493    pub properties: Vec<Expression>,
9494    #[serde(default)]
9495    pub key: Option<Box<Expression>>,
9496}
9497
9498/// IncludeProperty
9499#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9500#[cfg_attr(feature = "bindings", derive(TS))]
9501pub struct IncludeProperty {
9502    pub this: Box<Expression>,
9503    #[serde(default)]
9504    pub alias: Option<String>,
9505    #[serde(default)]
9506    pub column_def: Option<Box<Expression>>,
9507}
9508
9509/// Properties
9510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9511#[cfg_attr(feature = "bindings", derive(TS))]
9512pub struct Properties {
9513    #[serde(default)]
9514    pub expressions: Vec<Expression>,
9515}
9516
9517/// InputOutputFormat
9518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9519#[cfg_attr(feature = "bindings", derive(TS))]
9520pub struct InputOutputFormat {
9521    #[serde(default)]
9522    pub input_format: Option<Box<Expression>>,
9523    #[serde(default)]
9524    pub output_format: Option<Box<Expression>>,
9525}
9526
9527/// Reference
9528#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9529#[cfg_attr(feature = "bindings", derive(TS))]
9530pub struct Reference {
9531    pub this: Box<Expression>,
9532    #[serde(default)]
9533    pub expressions: Vec<Expression>,
9534    #[serde(default)]
9535    pub options: Vec<Expression>,
9536}
9537
9538/// QueryOption
9539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9540#[cfg_attr(feature = "bindings", derive(TS))]
9541pub struct QueryOption {
9542    pub this: Box<Expression>,
9543    #[serde(default)]
9544    pub expression: Option<Box<Expression>>,
9545}
9546
9547/// WithTableHint
9548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9549#[cfg_attr(feature = "bindings", derive(TS))]
9550pub struct WithTableHint {
9551    #[serde(default)]
9552    pub expressions: Vec<Expression>,
9553}
9554
9555/// IndexTableHint
9556#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9557#[cfg_attr(feature = "bindings", derive(TS))]
9558pub struct IndexTableHint {
9559    pub this: Box<Expression>,
9560    #[serde(default)]
9561    pub expressions: Vec<Expression>,
9562    #[serde(default)]
9563    pub target: Option<Box<Expression>>,
9564}
9565
9566/// Get
9567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9568#[cfg_attr(feature = "bindings", derive(TS))]
9569pub struct Get {
9570    pub this: Box<Expression>,
9571    #[serde(default)]
9572    pub target: Option<Box<Expression>>,
9573    #[serde(default)]
9574    pub properties: Vec<Expression>,
9575}
9576
9577/// SetOperation
9578#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9579#[cfg_attr(feature = "bindings", derive(TS))]
9580pub struct SetOperation {
9581    #[serde(default)]
9582    pub with_: Option<Box<Expression>>,
9583    pub this: Box<Expression>,
9584    pub expression: Box<Expression>,
9585    #[serde(default)]
9586    pub distinct: bool,
9587    #[serde(default)]
9588    pub by_name: Option<Box<Expression>>,
9589    #[serde(default)]
9590    pub side: Option<Box<Expression>>,
9591    #[serde(default)]
9592    pub kind: Option<String>,
9593    #[serde(default)]
9594    pub on: Option<Box<Expression>>,
9595}
9596
9597/// Var - Simple variable reference (for SQL variables, keywords as values)
9598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9599#[cfg_attr(feature = "bindings", derive(TS))]
9600pub struct Var {
9601    pub this: String,
9602}
9603
9604/// Variadic - represents VARIADIC prefix on function arguments (PostgreSQL)
9605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9606#[cfg_attr(feature = "bindings", derive(TS))]
9607pub struct Variadic {
9608    pub this: Box<Expression>,
9609}
9610
9611/// Version
9612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9613#[cfg_attr(feature = "bindings", derive(TS))]
9614pub struct Version {
9615    pub this: Box<Expression>,
9616    pub kind: String,
9617    #[serde(default)]
9618    pub expression: Option<Box<Expression>>,
9619}
9620
9621/// Schema
9622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9623#[cfg_attr(feature = "bindings", derive(TS))]
9624pub struct Schema {
9625    #[serde(default)]
9626    pub this: Option<Box<Expression>>,
9627    #[serde(default)]
9628    pub expressions: Vec<Expression>,
9629}
9630
9631/// Lock
9632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9633#[cfg_attr(feature = "bindings", derive(TS))]
9634pub struct Lock {
9635    #[serde(default)]
9636    pub update: Option<Box<Expression>>,
9637    #[serde(default)]
9638    pub expressions: Vec<Expression>,
9639    #[serde(default)]
9640    pub wait: Option<Box<Expression>>,
9641    #[serde(default)]
9642    pub key: Option<Box<Expression>>,
9643}
9644
9645/// TableSample - wraps an expression with a TABLESAMPLE clause
9646/// Used when TABLESAMPLE follows a non-Table expression (subquery, function, etc.)
9647#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9648#[cfg_attr(feature = "bindings", derive(TS))]
9649pub struct TableSample {
9650    /// The expression being sampled (subquery, function, etc.)
9651    #[serde(default, skip_serializing_if = "Option::is_none")]
9652    pub this: Option<Box<Expression>>,
9653    /// The sample specification
9654    #[serde(default, skip_serializing_if = "Option::is_none")]
9655    pub sample: Option<Box<Sample>>,
9656    #[serde(default)]
9657    pub expressions: Vec<Expression>,
9658    #[serde(default)]
9659    pub method: Option<String>,
9660    #[serde(default)]
9661    pub bucket_numerator: Option<Box<Expression>>,
9662    #[serde(default)]
9663    pub bucket_denominator: Option<Box<Expression>>,
9664    #[serde(default)]
9665    pub bucket_field: Option<Box<Expression>>,
9666    #[serde(default)]
9667    pub percent: Option<Box<Expression>>,
9668    #[serde(default)]
9669    pub rows: Option<Box<Expression>>,
9670    #[serde(default)]
9671    pub size: Option<i64>,
9672    #[serde(default)]
9673    pub seed: Option<Box<Expression>>,
9674}
9675
9676/// Tags are used for generating arbitrary sql like SELECT <span>x</span>.
9677#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9678#[cfg_attr(feature = "bindings", derive(TS))]
9679pub struct Tag {
9680    #[serde(default)]
9681    pub this: Option<Box<Expression>>,
9682    #[serde(default)]
9683    pub prefix: Option<Box<Expression>>,
9684    #[serde(default)]
9685    pub postfix: Option<Box<Expression>>,
9686}
9687
9688/// UnpivotColumns
9689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9690#[cfg_attr(feature = "bindings", derive(TS))]
9691pub struct UnpivotColumns {
9692    pub this: Box<Expression>,
9693    #[serde(default)]
9694    pub expressions: Vec<Expression>,
9695}
9696
9697/// SessionParameter
9698#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9699#[cfg_attr(feature = "bindings", derive(TS))]
9700pub struct SessionParameter {
9701    pub this: Box<Expression>,
9702    #[serde(default)]
9703    pub kind: Option<String>,
9704}
9705
9706/// PseudoType
9707#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9708#[cfg_attr(feature = "bindings", derive(TS))]
9709pub struct PseudoType {
9710    pub this: Box<Expression>,
9711}
9712
9713/// ObjectIdentifier
9714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9715#[cfg_attr(feature = "bindings", derive(TS))]
9716pub struct ObjectIdentifier {
9717    pub this: Box<Expression>,
9718}
9719
9720/// Transaction
9721#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9722#[cfg_attr(feature = "bindings", derive(TS))]
9723pub struct Transaction {
9724    #[serde(default)]
9725    pub this: Option<Box<Expression>>,
9726    #[serde(default)]
9727    pub modes: Option<Box<Expression>>,
9728    #[serde(default)]
9729    pub mark: Option<Box<Expression>>,
9730}
9731
9732/// Commit
9733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9734#[cfg_attr(feature = "bindings", derive(TS))]
9735pub struct Commit {
9736    #[serde(default)]
9737    pub chain: Option<Box<Expression>>,
9738    #[serde(default)]
9739    pub this: Option<Box<Expression>>,
9740    #[serde(default)]
9741    pub durability: Option<Box<Expression>>,
9742}
9743
9744/// Rollback
9745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9746#[cfg_attr(feature = "bindings", derive(TS))]
9747pub struct Rollback {
9748    #[serde(default)]
9749    pub savepoint: Option<Box<Expression>>,
9750    #[serde(default)]
9751    pub this: Option<Box<Expression>>,
9752}
9753
9754/// AlterSession
9755#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9756#[cfg_attr(feature = "bindings", derive(TS))]
9757pub struct AlterSession {
9758    #[serde(default)]
9759    pub expressions: Vec<Expression>,
9760    #[serde(default)]
9761    pub unset: Option<Box<Expression>>,
9762}
9763
9764/// Analyze
9765#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9766#[cfg_attr(feature = "bindings", derive(TS))]
9767pub struct Analyze {
9768    #[serde(default)]
9769    pub kind: Option<String>,
9770    #[serde(default)]
9771    pub this: Option<Box<Expression>>,
9772    #[serde(default)]
9773    pub options: Vec<Expression>,
9774    #[serde(default)]
9775    pub mode: Option<Box<Expression>>,
9776    #[serde(default)]
9777    pub partition: Option<Box<Expression>>,
9778    #[serde(default)]
9779    pub expression: Option<Box<Expression>>,
9780    #[serde(default)]
9781    pub properties: Vec<Expression>,
9782    /// Column list for ANALYZE tbl(col1, col2) syntax (PostgreSQL)
9783    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9784    pub columns: Vec<String>,
9785}
9786
9787/// AnalyzeStatistics
9788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9789#[cfg_attr(feature = "bindings", derive(TS))]
9790pub struct AnalyzeStatistics {
9791    pub kind: String,
9792    #[serde(default)]
9793    pub option: Option<Box<Expression>>,
9794    #[serde(default)]
9795    pub this: Option<Box<Expression>>,
9796    #[serde(default)]
9797    pub expressions: Vec<Expression>,
9798}
9799
9800/// AnalyzeHistogram
9801#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9802#[cfg_attr(feature = "bindings", derive(TS))]
9803pub struct AnalyzeHistogram {
9804    pub this: Box<Expression>,
9805    #[serde(default)]
9806    pub expressions: Vec<Expression>,
9807    #[serde(default)]
9808    pub expression: Option<Box<Expression>>,
9809    #[serde(default)]
9810    pub update_options: Option<Box<Expression>>,
9811}
9812
9813/// AnalyzeSample
9814#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9815#[cfg_attr(feature = "bindings", derive(TS))]
9816pub struct AnalyzeSample {
9817    pub kind: String,
9818    #[serde(default)]
9819    pub sample: Option<Box<Expression>>,
9820}
9821
9822/// AnalyzeListChainedRows
9823#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9824#[cfg_attr(feature = "bindings", derive(TS))]
9825pub struct AnalyzeListChainedRows {
9826    #[serde(default)]
9827    pub expression: Option<Box<Expression>>,
9828}
9829
9830/// AnalyzeDelete
9831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9832#[cfg_attr(feature = "bindings", derive(TS))]
9833pub struct AnalyzeDelete {
9834    #[serde(default)]
9835    pub kind: Option<String>,
9836}
9837
9838/// AnalyzeWith
9839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9840#[cfg_attr(feature = "bindings", derive(TS))]
9841pub struct AnalyzeWith {
9842    #[serde(default)]
9843    pub expressions: Vec<Expression>,
9844}
9845
9846/// AnalyzeValidate
9847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9848#[cfg_attr(feature = "bindings", derive(TS))]
9849pub struct AnalyzeValidate {
9850    pub kind: String,
9851    #[serde(default)]
9852    pub this: Option<Box<Expression>>,
9853    #[serde(default)]
9854    pub expression: Option<Box<Expression>>,
9855}
9856
9857/// AddPartition
9858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9859#[cfg_attr(feature = "bindings", derive(TS))]
9860pub struct AddPartition {
9861    pub this: Box<Expression>,
9862    #[serde(default)]
9863    pub exists: bool,
9864    #[serde(default)]
9865    pub location: Option<Box<Expression>>,
9866}
9867
9868/// AttachOption
9869#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9870#[cfg_attr(feature = "bindings", derive(TS))]
9871pub struct AttachOption {
9872    pub this: Box<Expression>,
9873    #[serde(default)]
9874    pub expression: Option<Box<Expression>>,
9875}
9876
9877/// DropPartition
9878#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9879#[cfg_attr(feature = "bindings", derive(TS))]
9880pub struct DropPartition {
9881    #[serde(default)]
9882    pub expressions: Vec<Expression>,
9883    #[serde(default)]
9884    pub exists: bool,
9885}
9886
9887/// ReplacePartition
9888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9889#[cfg_attr(feature = "bindings", derive(TS))]
9890pub struct ReplacePartition {
9891    pub expression: Box<Expression>,
9892    #[serde(default)]
9893    pub source: Option<Box<Expression>>,
9894}
9895
9896/// DPipe
9897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9898#[cfg_attr(feature = "bindings", derive(TS))]
9899pub struct DPipe {
9900    pub this: Box<Expression>,
9901    pub expression: Box<Expression>,
9902    #[serde(default)]
9903    pub safe: Option<Box<Expression>>,
9904}
9905
9906/// Operator
9907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9908#[cfg_attr(feature = "bindings", derive(TS))]
9909pub struct Operator {
9910    pub this: Box<Expression>,
9911    #[serde(default)]
9912    pub operator: Option<Box<Expression>>,
9913    pub expression: Box<Expression>,
9914    /// Comments between OPERATOR() and the RHS expression
9915    #[serde(default, skip_serializing_if = "Vec::is_empty")]
9916    pub comments: Vec<String>,
9917}
9918
9919/// PivotAny
9920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9921#[cfg_attr(feature = "bindings", derive(TS))]
9922pub struct PivotAny {
9923    #[serde(default)]
9924    pub this: Option<Box<Expression>>,
9925}
9926
9927/// Aliases
9928#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9929#[cfg_attr(feature = "bindings", derive(TS))]
9930pub struct Aliases {
9931    pub this: Box<Expression>,
9932    #[serde(default)]
9933    pub expressions: Vec<Expression>,
9934}
9935
9936/// AtIndex
9937#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9938#[cfg_attr(feature = "bindings", derive(TS))]
9939pub struct AtIndex {
9940    pub this: Box<Expression>,
9941    pub expression: Box<Expression>,
9942}
9943
9944/// FromTimeZone
9945#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9946#[cfg_attr(feature = "bindings", derive(TS))]
9947pub struct FromTimeZone {
9948    pub this: Box<Expression>,
9949    #[serde(default)]
9950    pub zone: Option<Box<Expression>>,
9951}
9952
9953/// Format override for a column in Teradata
9954#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9955#[cfg_attr(feature = "bindings", derive(TS))]
9956pub struct FormatPhrase {
9957    pub this: Box<Expression>,
9958    pub format: String,
9959}
9960
9961/// ForIn
9962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9963#[cfg_attr(feature = "bindings", derive(TS))]
9964pub struct ForIn {
9965    pub this: Box<Expression>,
9966    pub expression: Box<Expression>,
9967}
9968
9969/// Automatically converts unit arg into a var.
9970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9971#[cfg_attr(feature = "bindings", derive(TS))]
9972pub struct TimeUnit {
9973    #[serde(default)]
9974    pub unit: Option<String>,
9975}
9976
9977/// IntervalOp
9978#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9979#[cfg_attr(feature = "bindings", derive(TS))]
9980pub struct IntervalOp {
9981    #[serde(default)]
9982    pub unit: Option<String>,
9983    pub expression: Box<Expression>,
9984}
9985
9986/// HavingMax
9987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9988#[cfg_attr(feature = "bindings", derive(TS))]
9989pub struct HavingMax {
9990    pub this: Box<Expression>,
9991    pub expression: Box<Expression>,
9992    #[serde(default)]
9993    pub max: Option<Box<Expression>>,
9994}
9995
9996/// CosineDistance
9997#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9998#[cfg_attr(feature = "bindings", derive(TS))]
9999pub struct CosineDistance {
10000    pub this: Box<Expression>,
10001    pub expression: Box<Expression>,
10002}
10003
10004/// DotProduct
10005#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10006#[cfg_attr(feature = "bindings", derive(TS))]
10007pub struct DotProduct {
10008    pub this: Box<Expression>,
10009    pub expression: Box<Expression>,
10010}
10011
10012/// EuclideanDistance
10013#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10014#[cfg_attr(feature = "bindings", derive(TS))]
10015pub struct EuclideanDistance {
10016    pub this: Box<Expression>,
10017    pub expression: Box<Expression>,
10018}
10019
10020/// ManhattanDistance
10021#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10022#[cfg_attr(feature = "bindings", derive(TS))]
10023pub struct ManhattanDistance {
10024    pub this: Box<Expression>,
10025    pub expression: Box<Expression>,
10026}
10027
10028/// JarowinklerSimilarity
10029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10030#[cfg_attr(feature = "bindings", derive(TS))]
10031pub struct JarowinklerSimilarity {
10032    pub this: Box<Expression>,
10033    pub expression: Box<Expression>,
10034}
10035
10036/// Booland
10037#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10038#[cfg_attr(feature = "bindings", derive(TS))]
10039pub struct Booland {
10040    pub this: Box<Expression>,
10041    pub expression: Box<Expression>,
10042}
10043
10044/// Boolor
10045#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10046#[cfg_attr(feature = "bindings", derive(TS))]
10047pub struct Boolor {
10048    pub this: Box<Expression>,
10049    pub expression: Box<Expression>,
10050}
10051
10052/// ParameterizedAgg
10053#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10054#[cfg_attr(feature = "bindings", derive(TS))]
10055pub struct ParameterizedAgg {
10056    pub this: Box<Expression>,
10057    #[serde(default)]
10058    pub expressions: Vec<Expression>,
10059    #[serde(default)]
10060    pub params: Vec<Expression>,
10061}
10062
10063/// ArgMax
10064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10065#[cfg_attr(feature = "bindings", derive(TS))]
10066pub struct ArgMax {
10067    pub this: Box<Expression>,
10068    pub expression: Box<Expression>,
10069    #[serde(default)]
10070    pub count: Option<Box<Expression>>,
10071}
10072
10073/// ArgMin
10074#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10075#[cfg_attr(feature = "bindings", derive(TS))]
10076pub struct ArgMin {
10077    pub this: Box<Expression>,
10078    pub expression: Box<Expression>,
10079    #[serde(default)]
10080    pub count: Option<Box<Expression>>,
10081}
10082
10083/// ApproxTopK
10084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10085#[cfg_attr(feature = "bindings", derive(TS))]
10086pub struct ApproxTopK {
10087    pub this: Box<Expression>,
10088    #[serde(default)]
10089    pub expression: Option<Box<Expression>>,
10090    #[serde(default)]
10091    pub counters: Option<Box<Expression>>,
10092}
10093
10094/// ApproxTopKAccumulate
10095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10096#[cfg_attr(feature = "bindings", derive(TS))]
10097pub struct ApproxTopKAccumulate {
10098    pub this: Box<Expression>,
10099    #[serde(default)]
10100    pub expression: Option<Box<Expression>>,
10101}
10102
10103/// ApproxTopKCombine
10104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10105#[cfg_attr(feature = "bindings", derive(TS))]
10106pub struct ApproxTopKCombine {
10107    pub this: Box<Expression>,
10108    #[serde(default)]
10109    pub expression: Option<Box<Expression>>,
10110}
10111
10112/// ApproxTopKEstimate
10113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10114#[cfg_attr(feature = "bindings", derive(TS))]
10115pub struct ApproxTopKEstimate {
10116    pub this: Box<Expression>,
10117    #[serde(default)]
10118    pub expression: Option<Box<Expression>>,
10119}
10120
10121/// ApproxTopSum
10122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10123#[cfg_attr(feature = "bindings", derive(TS))]
10124pub struct ApproxTopSum {
10125    pub this: Box<Expression>,
10126    pub expression: Box<Expression>,
10127    #[serde(default)]
10128    pub count: Option<Box<Expression>>,
10129}
10130
10131/// ApproxQuantiles
10132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10133#[cfg_attr(feature = "bindings", derive(TS))]
10134pub struct ApproxQuantiles {
10135    pub this: Box<Expression>,
10136    #[serde(default)]
10137    pub expression: Option<Box<Expression>>,
10138}
10139
10140/// Minhash
10141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10142#[cfg_attr(feature = "bindings", derive(TS))]
10143pub struct Minhash {
10144    pub this: Box<Expression>,
10145    #[serde(default)]
10146    pub expressions: Vec<Expression>,
10147}
10148
10149/// FarmFingerprint
10150#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10151#[cfg_attr(feature = "bindings", derive(TS))]
10152pub struct FarmFingerprint {
10153    #[serde(default)]
10154    pub expressions: Vec<Expression>,
10155}
10156
10157/// Float64
10158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10159#[cfg_attr(feature = "bindings", derive(TS))]
10160pub struct Float64 {
10161    pub this: Box<Expression>,
10162    #[serde(default)]
10163    pub expression: Option<Box<Expression>>,
10164}
10165
10166/// Transform
10167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10168#[cfg_attr(feature = "bindings", derive(TS))]
10169pub struct Transform {
10170    pub this: Box<Expression>,
10171    pub expression: Box<Expression>,
10172}
10173
10174/// Translate
10175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10176#[cfg_attr(feature = "bindings", derive(TS))]
10177pub struct Translate {
10178    pub this: Box<Expression>,
10179    #[serde(default)]
10180    pub from_: Option<Box<Expression>>,
10181    #[serde(default)]
10182    pub to: Option<Box<Expression>>,
10183}
10184
10185/// Grouping
10186#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10187#[cfg_attr(feature = "bindings", derive(TS))]
10188pub struct Grouping {
10189    #[serde(default)]
10190    pub expressions: Vec<Expression>,
10191}
10192
10193/// GroupingId
10194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10195#[cfg_attr(feature = "bindings", derive(TS))]
10196pub struct GroupingId {
10197    #[serde(default)]
10198    pub expressions: Vec<Expression>,
10199}
10200
10201/// Anonymous
10202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10203#[cfg_attr(feature = "bindings", derive(TS))]
10204pub struct Anonymous {
10205    pub this: Box<Expression>,
10206    #[serde(default)]
10207    pub expressions: Vec<Expression>,
10208}
10209
10210/// AnonymousAggFunc
10211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10212#[cfg_attr(feature = "bindings", derive(TS))]
10213pub struct AnonymousAggFunc {
10214    pub this: Box<Expression>,
10215    #[serde(default)]
10216    pub expressions: Vec<Expression>,
10217}
10218
10219/// CombinedAggFunc
10220#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10221#[cfg_attr(feature = "bindings", derive(TS))]
10222pub struct CombinedAggFunc {
10223    pub this: Box<Expression>,
10224    #[serde(default)]
10225    pub expressions: Vec<Expression>,
10226}
10227
10228/// CombinedParameterizedAgg
10229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10230#[cfg_attr(feature = "bindings", derive(TS))]
10231pub struct CombinedParameterizedAgg {
10232    pub this: Box<Expression>,
10233    #[serde(default)]
10234    pub expressions: Vec<Expression>,
10235    #[serde(default)]
10236    pub params: Vec<Expression>,
10237}
10238
10239/// HashAgg
10240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10241#[cfg_attr(feature = "bindings", derive(TS))]
10242pub struct HashAgg {
10243    pub this: Box<Expression>,
10244    #[serde(default)]
10245    pub expressions: Vec<Expression>,
10246}
10247
10248/// Hll
10249#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10250#[cfg_attr(feature = "bindings", derive(TS))]
10251pub struct Hll {
10252    pub this: Box<Expression>,
10253    #[serde(default)]
10254    pub expressions: Vec<Expression>,
10255}
10256
10257/// Apply
10258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10259#[cfg_attr(feature = "bindings", derive(TS))]
10260pub struct Apply {
10261    pub this: Box<Expression>,
10262    pub expression: Box<Expression>,
10263}
10264
10265/// ToBoolean
10266#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10267#[cfg_attr(feature = "bindings", derive(TS))]
10268pub struct ToBoolean {
10269    pub this: Box<Expression>,
10270    #[serde(default)]
10271    pub safe: Option<Box<Expression>>,
10272}
10273
10274/// List
10275#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10276#[cfg_attr(feature = "bindings", derive(TS))]
10277pub struct List {
10278    #[serde(default)]
10279    pub expressions: Vec<Expression>,
10280}
10281
10282/// ToMap - Materialize-style map constructor
10283/// Can hold either:
10284/// - A SELECT subquery (MAP(SELECT 'a', 1))
10285/// - A struct with key=>value entries (MAP['a' => 1, 'b' => 2])
10286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10287#[cfg_attr(feature = "bindings", derive(TS))]
10288pub struct ToMap {
10289    /// Either a Select subquery or a Struct containing PropertyEQ entries
10290    pub this: Box<Expression>,
10291}
10292
10293/// Pad
10294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10295#[cfg_attr(feature = "bindings", derive(TS))]
10296pub struct Pad {
10297    pub this: Box<Expression>,
10298    pub expression: Box<Expression>,
10299    #[serde(default)]
10300    pub fill_pattern: Option<Box<Expression>>,
10301    #[serde(default)]
10302    pub is_left: Option<Box<Expression>>,
10303}
10304
10305/// ToChar
10306#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10307#[cfg_attr(feature = "bindings", derive(TS))]
10308pub struct ToChar {
10309    pub this: Box<Expression>,
10310    #[serde(default)]
10311    pub format: Option<String>,
10312    #[serde(default)]
10313    pub nlsparam: Option<Box<Expression>>,
10314    #[serde(default)]
10315    pub is_numeric: Option<Box<Expression>>,
10316}
10317
10318/// StringFunc - String type conversion function (BigQuery STRING)
10319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10320#[cfg_attr(feature = "bindings", derive(TS))]
10321pub struct StringFunc {
10322    pub this: Box<Expression>,
10323    #[serde(default)]
10324    pub zone: Option<Box<Expression>>,
10325}
10326
10327/// ToNumber
10328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10329#[cfg_attr(feature = "bindings", derive(TS))]
10330pub struct ToNumber {
10331    pub this: Box<Expression>,
10332    #[serde(default)]
10333    pub format: Option<Box<Expression>>,
10334    #[serde(default)]
10335    pub nlsparam: Option<Box<Expression>>,
10336    #[serde(default)]
10337    pub precision: Option<Box<Expression>>,
10338    #[serde(default)]
10339    pub scale: Option<Box<Expression>>,
10340    #[serde(default)]
10341    pub safe: Option<Box<Expression>>,
10342    #[serde(default)]
10343    pub safe_name: Option<Box<Expression>>,
10344}
10345
10346/// ToDouble
10347#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10348#[cfg_attr(feature = "bindings", derive(TS))]
10349pub struct ToDouble {
10350    pub this: Box<Expression>,
10351    #[serde(default)]
10352    pub format: Option<String>,
10353    #[serde(default)]
10354    pub safe: Option<Box<Expression>>,
10355}
10356
10357/// ToDecfloat
10358#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10359#[cfg_attr(feature = "bindings", derive(TS))]
10360pub struct ToDecfloat {
10361    pub this: Box<Expression>,
10362    #[serde(default)]
10363    pub format: Option<String>,
10364}
10365
10366/// TryToDecfloat
10367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10368#[cfg_attr(feature = "bindings", derive(TS))]
10369pub struct TryToDecfloat {
10370    pub this: Box<Expression>,
10371    #[serde(default)]
10372    pub format: Option<String>,
10373}
10374
10375/// ToFile
10376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10377#[cfg_attr(feature = "bindings", derive(TS))]
10378pub struct ToFile {
10379    pub this: Box<Expression>,
10380    #[serde(default)]
10381    pub path: Option<Box<Expression>>,
10382    #[serde(default)]
10383    pub safe: Option<Box<Expression>>,
10384}
10385
10386/// Columns
10387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10388#[cfg_attr(feature = "bindings", derive(TS))]
10389pub struct Columns {
10390    pub this: Box<Expression>,
10391    #[serde(default)]
10392    pub unpack: Option<Box<Expression>>,
10393}
10394
10395/// ConvertToCharset
10396#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10397#[cfg_attr(feature = "bindings", derive(TS))]
10398pub struct ConvertToCharset {
10399    pub this: Box<Expression>,
10400    #[serde(default)]
10401    pub dest: Option<Box<Expression>>,
10402    #[serde(default)]
10403    pub source: Option<Box<Expression>>,
10404}
10405
10406/// ConvertTimezone
10407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10408#[cfg_attr(feature = "bindings", derive(TS))]
10409pub struct ConvertTimezone {
10410    #[serde(default)]
10411    pub source_tz: Option<Box<Expression>>,
10412    #[serde(default)]
10413    pub target_tz: Option<Box<Expression>>,
10414    #[serde(default)]
10415    pub timestamp: Option<Box<Expression>>,
10416    #[serde(default)]
10417    pub options: Vec<Expression>,
10418}
10419
10420/// GenerateSeries
10421#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10422#[cfg_attr(feature = "bindings", derive(TS))]
10423pub struct GenerateSeries {
10424    #[serde(default)]
10425    pub start: Option<Box<Expression>>,
10426    #[serde(default)]
10427    pub end: Option<Box<Expression>>,
10428    #[serde(default)]
10429    pub step: Option<Box<Expression>>,
10430    #[serde(default)]
10431    pub is_end_exclusive: Option<Box<Expression>>,
10432}
10433
10434/// AIAgg
10435#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10436#[cfg_attr(feature = "bindings", derive(TS))]
10437pub struct AIAgg {
10438    pub this: Box<Expression>,
10439    pub expression: Box<Expression>,
10440}
10441
10442/// AIClassify
10443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10444#[cfg_attr(feature = "bindings", derive(TS))]
10445pub struct AIClassify {
10446    pub this: Box<Expression>,
10447    #[serde(default)]
10448    pub categories: Option<Box<Expression>>,
10449    #[serde(default)]
10450    pub config: Option<Box<Expression>>,
10451}
10452
10453/// ArrayAll
10454#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10455#[cfg_attr(feature = "bindings", derive(TS))]
10456pub struct ArrayAll {
10457    pub this: Box<Expression>,
10458    pub expression: Box<Expression>,
10459}
10460
10461/// ArrayAny
10462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10463#[cfg_attr(feature = "bindings", derive(TS))]
10464pub struct ArrayAny {
10465    pub this: Box<Expression>,
10466    pub expression: Box<Expression>,
10467}
10468
10469/// ArrayConstructCompact
10470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10471#[cfg_attr(feature = "bindings", derive(TS))]
10472pub struct ArrayConstructCompact {
10473    #[serde(default)]
10474    pub expressions: Vec<Expression>,
10475}
10476
10477/// StPoint
10478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10479#[cfg_attr(feature = "bindings", derive(TS))]
10480pub struct StPoint {
10481    pub this: Box<Expression>,
10482    pub expression: Box<Expression>,
10483    #[serde(default)]
10484    pub null: Option<Box<Expression>>,
10485}
10486
10487/// StDistance
10488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10489#[cfg_attr(feature = "bindings", derive(TS))]
10490pub struct StDistance {
10491    pub this: Box<Expression>,
10492    pub expression: Box<Expression>,
10493    #[serde(default)]
10494    pub use_spheroid: Option<Box<Expression>>,
10495}
10496
10497/// StringToArray
10498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10499#[cfg_attr(feature = "bindings", derive(TS))]
10500pub struct StringToArray {
10501    pub this: Box<Expression>,
10502    #[serde(default)]
10503    pub expression: Option<Box<Expression>>,
10504    #[serde(default)]
10505    pub null: Option<Box<Expression>>,
10506}
10507
10508/// ArraySum
10509#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10510#[cfg_attr(feature = "bindings", derive(TS))]
10511pub struct ArraySum {
10512    pub this: Box<Expression>,
10513    #[serde(default)]
10514    pub expression: Option<Box<Expression>>,
10515}
10516
10517/// ObjectAgg
10518#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10519#[cfg_attr(feature = "bindings", derive(TS))]
10520pub struct ObjectAgg {
10521    pub this: Box<Expression>,
10522    pub expression: Box<Expression>,
10523}
10524
10525/// CastToStrType
10526#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10527#[cfg_attr(feature = "bindings", derive(TS))]
10528pub struct CastToStrType {
10529    pub this: Box<Expression>,
10530    #[serde(default)]
10531    pub to: Option<Box<Expression>>,
10532}
10533
10534/// CheckJson
10535#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10536#[cfg_attr(feature = "bindings", derive(TS))]
10537pub struct CheckJson {
10538    pub this: Box<Expression>,
10539}
10540
10541/// CheckXml
10542#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10543#[cfg_attr(feature = "bindings", derive(TS))]
10544pub struct CheckXml {
10545    pub this: Box<Expression>,
10546    #[serde(default)]
10547    pub disable_auto_convert: Option<Box<Expression>>,
10548}
10549
10550/// TranslateCharacters
10551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10552#[cfg_attr(feature = "bindings", derive(TS))]
10553pub struct TranslateCharacters {
10554    pub this: Box<Expression>,
10555    pub expression: Box<Expression>,
10556    #[serde(default)]
10557    pub with_error: Option<Box<Expression>>,
10558}
10559
10560/// CurrentSchemas
10561#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10562#[cfg_attr(feature = "bindings", derive(TS))]
10563pub struct CurrentSchemas {
10564    #[serde(default)]
10565    pub this: Option<Box<Expression>>,
10566}
10567
10568/// CurrentDatetime
10569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10570#[cfg_attr(feature = "bindings", derive(TS))]
10571pub struct CurrentDatetime {
10572    #[serde(default)]
10573    pub this: Option<Box<Expression>>,
10574}
10575
10576/// Localtime
10577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10578#[cfg_attr(feature = "bindings", derive(TS))]
10579pub struct Localtime {
10580    #[serde(default)]
10581    pub this: Option<Box<Expression>>,
10582}
10583
10584/// Localtimestamp
10585#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10586#[cfg_attr(feature = "bindings", derive(TS))]
10587pub struct Localtimestamp {
10588    #[serde(default)]
10589    pub this: Option<Box<Expression>>,
10590}
10591
10592/// Systimestamp
10593#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10594#[cfg_attr(feature = "bindings", derive(TS))]
10595pub struct Systimestamp {
10596    #[serde(default)]
10597    pub this: Option<Box<Expression>>,
10598}
10599
10600/// CurrentSchema
10601#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10602#[cfg_attr(feature = "bindings", derive(TS))]
10603pub struct CurrentSchema {
10604    #[serde(default)]
10605    pub this: Option<Box<Expression>>,
10606}
10607
10608/// CurrentUser
10609#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10610#[cfg_attr(feature = "bindings", derive(TS))]
10611pub struct CurrentUser {
10612    #[serde(default)]
10613    pub this: Option<Box<Expression>>,
10614}
10615
10616/// SessionUser - MySQL/PostgreSQL SESSION_USER function
10617#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10618#[cfg_attr(feature = "bindings", derive(TS))]
10619pub struct SessionUser;
10620
10621/// JSONPathRoot - Represents $ in JSON path expressions
10622#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10623#[cfg_attr(feature = "bindings", derive(TS))]
10624pub struct JSONPathRoot;
10625
10626/// UtcTime
10627#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10628#[cfg_attr(feature = "bindings", derive(TS))]
10629pub struct UtcTime {
10630    #[serde(default)]
10631    pub this: Option<Box<Expression>>,
10632}
10633
10634/// UtcTimestamp
10635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10636#[cfg_attr(feature = "bindings", derive(TS))]
10637pub struct UtcTimestamp {
10638    #[serde(default)]
10639    pub this: Option<Box<Expression>>,
10640}
10641
10642/// TimestampFunc - TIMESTAMP constructor function
10643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10644#[cfg_attr(feature = "bindings", derive(TS))]
10645pub struct TimestampFunc {
10646    #[serde(default)]
10647    pub this: Option<Box<Expression>>,
10648    #[serde(default)]
10649    pub zone: Option<Box<Expression>>,
10650    #[serde(default)]
10651    pub with_tz: Option<bool>,
10652    #[serde(default)]
10653    pub safe: Option<bool>,
10654}
10655
10656/// DateBin
10657#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10658#[cfg_attr(feature = "bindings", derive(TS))]
10659pub struct DateBin {
10660    pub this: Box<Expression>,
10661    pub expression: Box<Expression>,
10662    #[serde(default)]
10663    pub unit: Option<String>,
10664    #[serde(default)]
10665    pub zone: Option<Box<Expression>>,
10666    #[serde(default)]
10667    pub origin: Option<Box<Expression>>,
10668}
10669
10670/// Datetime
10671#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10672#[cfg_attr(feature = "bindings", derive(TS))]
10673pub struct Datetime {
10674    pub this: Box<Expression>,
10675    #[serde(default)]
10676    pub expression: Option<Box<Expression>>,
10677}
10678
10679/// DatetimeAdd
10680#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10681#[cfg_attr(feature = "bindings", derive(TS))]
10682pub struct DatetimeAdd {
10683    pub this: Box<Expression>,
10684    pub expression: Box<Expression>,
10685    #[serde(default)]
10686    pub unit: Option<String>,
10687}
10688
10689/// DatetimeSub
10690#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10691#[cfg_attr(feature = "bindings", derive(TS))]
10692pub struct DatetimeSub {
10693    pub this: Box<Expression>,
10694    pub expression: Box<Expression>,
10695    #[serde(default)]
10696    pub unit: Option<String>,
10697}
10698
10699/// DatetimeDiff
10700#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10701#[cfg_attr(feature = "bindings", derive(TS))]
10702pub struct DatetimeDiff {
10703    pub this: Box<Expression>,
10704    pub expression: Box<Expression>,
10705    #[serde(default)]
10706    pub unit: Option<String>,
10707}
10708
10709/// DatetimeTrunc
10710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10711#[cfg_attr(feature = "bindings", derive(TS))]
10712pub struct DatetimeTrunc {
10713    pub this: Box<Expression>,
10714    pub unit: String,
10715    #[serde(default)]
10716    pub zone: Option<Box<Expression>>,
10717}
10718
10719/// Dayname
10720#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10721#[cfg_attr(feature = "bindings", derive(TS))]
10722pub struct Dayname {
10723    pub this: Box<Expression>,
10724    #[serde(default)]
10725    pub abbreviated: Option<Box<Expression>>,
10726}
10727
10728/// MakeInterval
10729#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10730#[cfg_attr(feature = "bindings", derive(TS))]
10731pub struct MakeInterval {
10732    #[serde(default)]
10733    pub year: Option<Box<Expression>>,
10734    #[serde(default)]
10735    pub month: Option<Box<Expression>>,
10736    #[serde(default)]
10737    pub week: Option<Box<Expression>>,
10738    #[serde(default)]
10739    pub day: Option<Box<Expression>>,
10740    #[serde(default)]
10741    pub hour: Option<Box<Expression>>,
10742    #[serde(default)]
10743    pub minute: Option<Box<Expression>>,
10744    #[serde(default)]
10745    pub second: Option<Box<Expression>>,
10746}
10747
10748/// PreviousDay
10749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10750#[cfg_attr(feature = "bindings", derive(TS))]
10751pub struct PreviousDay {
10752    pub this: Box<Expression>,
10753    pub expression: Box<Expression>,
10754}
10755
10756/// Elt
10757#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10758#[cfg_attr(feature = "bindings", derive(TS))]
10759pub struct Elt {
10760    pub this: Box<Expression>,
10761    #[serde(default)]
10762    pub expressions: Vec<Expression>,
10763}
10764
10765/// TimestampAdd
10766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10767#[cfg_attr(feature = "bindings", derive(TS))]
10768pub struct TimestampAdd {
10769    pub this: Box<Expression>,
10770    pub expression: Box<Expression>,
10771    #[serde(default)]
10772    pub unit: Option<String>,
10773}
10774
10775/// TimestampSub
10776#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10777#[cfg_attr(feature = "bindings", derive(TS))]
10778pub struct TimestampSub {
10779    pub this: Box<Expression>,
10780    pub expression: Box<Expression>,
10781    #[serde(default)]
10782    pub unit: Option<String>,
10783}
10784
10785/// TimestampDiff
10786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10787#[cfg_attr(feature = "bindings", derive(TS))]
10788pub struct TimestampDiff {
10789    pub this: Box<Expression>,
10790    pub expression: Box<Expression>,
10791    #[serde(default)]
10792    pub unit: Option<String>,
10793}
10794
10795/// TimeSlice
10796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10797#[cfg_attr(feature = "bindings", derive(TS))]
10798pub struct TimeSlice {
10799    pub this: Box<Expression>,
10800    pub expression: Box<Expression>,
10801    pub unit: String,
10802    #[serde(default)]
10803    pub kind: Option<String>,
10804}
10805
10806/// TimeAdd
10807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10808#[cfg_attr(feature = "bindings", derive(TS))]
10809pub struct TimeAdd {
10810    pub this: Box<Expression>,
10811    pub expression: Box<Expression>,
10812    #[serde(default)]
10813    pub unit: Option<String>,
10814}
10815
10816/// TimeSub
10817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10818#[cfg_attr(feature = "bindings", derive(TS))]
10819pub struct TimeSub {
10820    pub this: Box<Expression>,
10821    pub expression: Box<Expression>,
10822    #[serde(default)]
10823    pub unit: Option<String>,
10824}
10825
10826/// TimeDiff
10827#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10828#[cfg_attr(feature = "bindings", derive(TS))]
10829pub struct TimeDiff {
10830    pub this: Box<Expression>,
10831    pub expression: Box<Expression>,
10832    #[serde(default)]
10833    pub unit: Option<String>,
10834}
10835
10836/// TimeTrunc
10837#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10838#[cfg_attr(feature = "bindings", derive(TS))]
10839pub struct TimeTrunc {
10840    pub this: Box<Expression>,
10841    pub unit: String,
10842    #[serde(default)]
10843    pub zone: Option<Box<Expression>>,
10844}
10845
10846/// DateFromParts
10847#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10848#[cfg_attr(feature = "bindings", derive(TS))]
10849pub struct DateFromParts {
10850    #[serde(default)]
10851    pub year: Option<Box<Expression>>,
10852    #[serde(default)]
10853    pub month: Option<Box<Expression>>,
10854    #[serde(default)]
10855    pub day: Option<Box<Expression>>,
10856    #[serde(default)]
10857    pub allow_overflow: Option<Box<Expression>>,
10858}
10859
10860/// TimeFromParts
10861#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10862#[cfg_attr(feature = "bindings", derive(TS))]
10863pub struct TimeFromParts {
10864    #[serde(default)]
10865    pub hour: Option<Box<Expression>>,
10866    #[serde(default)]
10867    pub min: Option<Box<Expression>>,
10868    #[serde(default)]
10869    pub sec: Option<Box<Expression>>,
10870    #[serde(default)]
10871    pub nano: Option<Box<Expression>>,
10872    #[serde(default)]
10873    pub fractions: Option<Box<Expression>>,
10874    #[serde(default)]
10875    pub precision: Option<i64>,
10876}
10877
10878/// DecodeCase
10879#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10880#[cfg_attr(feature = "bindings", derive(TS))]
10881pub struct DecodeCase {
10882    #[serde(default)]
10883    pub expressions: Vec<Expression>,
10884}
10885
10886/// Decrypt
10887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10888#[cfg_attr(feature = "bindings", derive(TS))]
10889pub struct Decrypt {
10890    pub this: Box<Expression>,
10891    #[serde(default)]
10892    pub passphrase: Option<Box<Expression>>,
10893    #[serde(default)]
10894    pub aad: Option<Box<Expression>>,
10895    #[serde(default)]
10896    pub encryption_method: Option<Box<Expression>>,
10897    #[serde(default)]
10898    pub safe: Option<Box<Expression>>,
10899}
10900
10901/// DecryptRaw
10902#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10903#[cfg_attr(feature = "bindings", derive(TS))]
10904pub struct DecryptRaw {
10905    pub this: Box<Expression>,
10906    #[serde(default)]
10907    pub key: Option<Box<Expression>>,
10908    #[serde(default)]
10909    pub iv: Option<Box<Expression>>,
10910    #[serde(default)]
10911    pub aad: Option<Box<Expression>>,
10912    #[serde(default)]
10913    pub encryption_method: Option<Box<Expression>>,
10914    #[serde(default)]
10915    pub aead: Option<Box<Expression>>,
10916    #[serde(default)]
10917    pub safe: Option<Box<Expression>>,
10918}
10919
10920/// Encode
10921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10922#[cfg_attr(feature = "bindings", derive(TS))]
10923pub struct Encode {
10924    pub this: Box<Expression>,
10925    #[serde(default)]
10926    pub charset: Option<Box<Expression>>,
10927}
10928
10929/// Encrypt
10930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10931#[cfg_attr(feature = "bindings", derive(TS))]
10932pub struct Encrypt {
10933    pub this: Box<Expression>,
10934    #[serde(default)]
10935    pub passphrase: Option<Box<Expression>>,
10936    #[serde(default)]
10937    pub aad: Option<Box<Expression>>,
10938    #[serde(default)]
10939    pub encryption_method: Option<Box<Expression>>,
10940}
10941
10942/// EncryptRaw
10943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10944#[cfg_attr(feature = "bindings", derive(TS))]
10945pub struct EncryptRaw {
10946    pub this: Box<Expression>,
10947    #[serde(default)]
10948    pub key: Option<Box<Expression>>,
10949    #[serde(default)]
10950    pub iv: Option<Box<Expression>>,
10951    #[serde(default)]
10952    pub aad: Option<Box<Expression>>,
10953    #[serde(default)]
10954    pub encryption_method: Option<Box<Expression>>,
10955}
10956
10957/// EqualNull
10958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10959#[cfg_attr(feature = "bindings", derive(TS))]
10960pub struct EqualNull {
10961    pub this: Box<Expression>,
10962    pub expression: Box<Expression>,
10963}
10964
10965/// ToBinary
10966#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10967#[cfg_attr(feature = "bindings", derive(TS))]
10968pub struct ToBinary {
10969    pub this: Box<Expression>,
10970    #[serde(default)]
10971    pub format: Option<String>,
10972    #[serde(default)]
10973    pub safe: Option<Box<Expression>>,
10974}
10975
10976/// Base64DecodeBinary
10977#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10978#[cfg_attr(feature = "bindings", derive(TS))]
10979pub struct Base64DecodeBinary {
10980    pub this: Box<Expression>,
10981    #[serde(default)]
10982    pub alphabet: Option<Box<Expression>>,
10983}
10984
10985/// Base64DecodeString
10986#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10987#[cfg_attr(feature = "bindings", derive(TS))]
10988pub struct Base64DecodeString {
10989    pub this: Box<Expression>,
10990    #[serde(default)]
10991    pub alphabet: Option<Box<Expression>>,
10992}
10993
10994/// Base64Encode
10995#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10996#[cfg_attr(feature = "bindings", derive(TS))]
10997pub struct Base64Encode {
10998    pub this: Box<Expression>,
10999    #[serde(default)]
11000    pub max_line_length: Option<Box<Expression>>,
11001    #[serde(default)]
11002    pub alphabet: Option<Box<Expression>>,
11003}
11004
11005/// TryBase64DecodeBinary
11006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11007#[cfg_attr(feature = "bindings", derive(TS))]
11008pub struct TryBase64DecodeBinary {
11009    pub this: Box<Expression>,
11010    #[serde(default)]
11011    pub alphabet: Option<Box<Expression>>,
11012}
11013
11014/// TryBase64DecodeString
11015#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11016#[cfg_attr(feature = "bindings", derive(TS))]
11017pub struct TryBase64DecodeString {
11018    pub this: Box<Expression>,
11019    #[serde(default)]
11020    pub alphabet: Option<Box<Expression>>,
11021}
11022
11023/// GapFill
11024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11025#[cfg_attr(feature = "bindings", derive(TS))]
11026pub struct GapFill {
11027    pub this: Box<Expression>,
11028    #[serde(default)]
11029    pub ts_column: Option<Box<Expression>>,
11030    #[serde(default)]
11031    pub bucket_width: Option<Box<Expression>>,
11032    #[serde(default)]
11033    pub partitioning_columns: Option<Box<Expression>>,
11034    #[serde(default)]
11035    pub value_columns: Option<Box<Expression>>,
11036    #[serde(default)]
11037    pub origin: Option<Box<Expression>>,
11038    #[serde(default)]
11039    pub ignore_nulls: Option<Box<Expression>>,
11040}
11041
11042/// GenerateDateArray
11043#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11044#[cfg_attr(feature = "bindings", derive(TS))]
11045pub struct GenerateDateArray {
11046    #[serde(default)]
11047    pub start: Option<Box<Expression>>,
11048    #[serde(default)]
11049    pub end: Option<Box<Expression>>,
11050    #[serde(default)]
11051    pub step: Option<Box<Expression>>,
11052}
11053
11054/// GenerateTimestampArray
11055#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11056#[cfg_attr(feature = "bindings", derive(TS))]
11057pub struct GenerateTimestampArray {
11058    #[serde(default)]
11059    pub start: Option<Box<Expression>>,
11060    #[serde(default)]
11061    pub end: Option<Box<Expression>>,
11062    #[serde(default)]
11063    pub step: Option<Box<Expression>>,
11064}
11065
11066/// GetExtract
11067#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11068#[cfg_attr(feature = "bindings", derive(TS))]
11069pub struct GetExtract {
11070    pub this: Box<Expression>,
11071    pub expression: Box<Expression>,
11072}
11073
11074/// Getbit
11075#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11076#[cfg_attr(feature = "bindings", derive(TS))]
11077pub struct Getbit {
11078    pub this: Box<Expression>,
11079    pub expression: Box<Expression>,
11080    #[serde(default)]
11081    pub zero_is_msb: Option<Box<Expression>>,
11082}
11083
11084/// OverflowTruncateBehavior
11085#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11086#[cfg_attr(feature = "bindings", derive(TS))]
11087pub struct OverflowTruncateBehavior {
11088    #[serde(default)]
11089    pub this: Option<Box<Expression>>,
11090    #[serde(default)]
11091    pub with_count: Option<Box<Expression>>,
11092}
11093
11094/// HexEncode
11095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11096#[cfg_attr(feature = "bindings", derive(TS))]
11097pub struct HexEncode {
11098    pub this: Box<Expression>,
11099    #[serde(default)]
11100    pub case: Option<Box<Expression>>,
11101}
11102
11103/// Compress
11104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11105#[cfg_attr(feature = "bindings", derive(TS))]
11106pub struct Compress {
11107    pub this: Box<Expression>,
11108    #[serde(default)]
11109    pub method: Option<String>,
11110}
11111
11112/// DecompressBinary
11113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11114#[cfg_attr(feature = "bindings", derive(TS))]
11115pub struct DecompressBinary {
11116    pub this: Box<Expression>,
11117    pub method: String,
11118}
11119
11120/// DecompressString
11121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11122#[cfg_attr(feature = "bindings", derive(TS))]
11123pub struct DecompressString {
11124    pub this: Box<Expression>,
11125    pub method: String,
11126}
11127
11128/// Xor
11129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11130#[cfg_attr(feature = "bindings", derive(TS))]
11131pub struct Xor {
11132    #[serde(default)]
11133    pub this: Option<Box<Expression>>,
11134    #[serde(default)]
11135    pub expression: Option<Box<Expression>>,
11136    #[serde(default)]
11137    pub expressions: Vec<Expression>,
11138}
11139
11140/// Nullif
11141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11142#[cfg_attr(feature = "bindings", derive(TS))]
11143pub struct Nullif {
11144    pub this: Box<Expression>,
11145    pub expression: Box<Expression>,
11146}
11147
11148/// JSON
11149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11150#[cfg_attr(feature = "bindings", derive(TS))]
11151pub struct JSON {
11152    #[serde(default)]
11153    pub this: Option<Box<Expression>>,
11154    #[serde(default)]
11155    pub with_: Option<Box<Expression>>,
11156    #[serde(default)]
11157    pub unique: bool,
11158}
11159
11160/// JSONPath
11161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11162#[cfg_attr(feature = "bindings", derive(TS))]
11163pub struct JSONPath {
11164    #[serde(default)]
11165    pub expressions: Vec<Expression>,
11166    #[serde(default)]
11167    pub escape: Option<Box<Expression>>,
11168}
11169
11170/// JSONPathFilter
11171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11172#[cfg_attr(feature = "bindings", derive(TS))]
11173pub struct JSONPathFilter {
11174    pub this: Box<Expression>,
11175}
11176
11177/// JSONPathKey
11178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11179#[cfg_attr(feature = "bindings", derive(TS))]
11180pub struct JSONPathKey {
11181    pub this: Box<Expression>,
11182}
11183
11184/// JSONPathRecursive
11185#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11186#[cfg_attr(feature = "bindings", derive(TS))]
11187pub struct JSONPathRecursive {
11188    #[serde(default)]
11189    pub this: Option<Box<Expression>>,
11190}
11191
11192/// JSONPathScript
11193#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11194#[cfg_attr(feature = "bindings", derive(TS))]
11195pub struct JSONPathScript {
11196    pub this: Box<Expression>,
11197}
11198
11199/// JSONPathSlice
11200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11201#[cfg_attr(feature = "bindings", derive(TS))]
11202pub struct JSONPathSlice {
11203    #[serde(default)]
11204    pub start: Option<Box<Expression>>,
11205    #[serde(default)]
11206    pub end: Option<Box<Expression>>,
11207    #[serde(default)]
11208    pub step: Option<Box<Expression>>,
11209}
11210
11211/// JSONPathSelector
11212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11213#[cfg_attr(feature = "bindings", derive(TS))]
11214pub struct JSONPathSelector {
11215    pub this: Box<Expression>,
11216}
11217
11218/// JSONPathSubscript
11219#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11220#[cfg_attr(feature = "bindings", derive(TS))]
11221pub struct JSONPathSubscript {
11222    pub this: Box<Expression>,
11223}
11224
11225/// JSONPathUnion
11226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11227#[cfg_attr(feature = "bindings", derive(TS))]
11228pub struct JSONPathUnion {
11229    #[serde(default)]
11230    pub expressions: Vec<Expression>,
11231}
11232
11233/// Format
11234#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11235#[cfg_attr(feature = "bindings", derive(TS))]
11236pub struct Format {
11237    pub this: Box<Expression>,
11238    #[serde(default)]
11239    pub expressions: Vec<Expression>,
11240}
11241
11242/// JSONKeys
11243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11244#[cfg_attr(feature = "bindings", derive(TS))]
11245pub struct JSONKeys {
11246    pub this: Box<Expression>,
11247    #[serde(default)]
11248    pub expression: Option<Box<Expression>>,
11249    #[serde(default)]
11250    pub expressions: Vec<Expression>,
11251}
11252
11253/// JSONKeyValue
11254#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11255#[cfg_attr(feature = "bindings", derive(TS))]
11256pub struct JSONKeyValue {
11257    pub this: Box<Expression>,
11258    pub expression: Box<Expression>,
11259}
11260
11261/// JSONKeysAtDepth
11262#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11263#[cfg_attr(feature = "bindings", derive(TS))]
11264pub struct JSONKeysAtDepth {
11265    pub this: Box<Expression>,
11266    #[serde(default)]
11267    pub expression: Option<Box<Expression>>,
11268    #[serde(default)]
11269    pub mode: Option<Box<Expression>>,
11270}
11271
11272/// JSONObject
11273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11274#[cfg_attr(feature = "bindings", derive(TS))]
11275pub struct JSONObject {
11276    #[serde(default)]
11277    pub expressions: Vec<Expression>,
11278    #[serde(default)]
11279    pub null_handling: Option<Box<Expression>>,
11280    #[serde(default)]
11281    pub unique_keys: Option<Box<Expression>>,
11282    #[serde(default)]
11283    pub return_type: Option<Box<Expression>>,
11284    #[serde(default)]
11285    pub encoding: Option<Box<Expression>>,
11286}
11287
11288/// JSONObjectAgg
11289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11290#[cfg_attr(feature = "bindings", derive(TS))]
11291pub struct JSONObjectAgg {
11292    #[serde(default)]
11293    pub expressions: Vec<Expression>,
11294    #[serde(default)]
11295    pub null_handling: Option<Box<Expression>>,
11296    #[serde(default)]
11297    pub unique_keys: Option<Box<Expression>>,
11298    #[serde(default)]
11299    pub return_type: Option<Box<Expression>>,
11300    #[serde(default)]
11301    pub encoding: Option<Box<Expression>>,
11302}
11303
11304/// JSONBObjectAgg
11305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11306#[cfg_attr(feature = "bindings", derive(TS))]
11307pub struct JSONBObjectAgg {
11308    pub this: Box<Expression>,
11309    pub expression: Box<Expression>,
11310}
11311
11312/// JSONArray
11313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11314#[cfg_attr(feature = "bindings", derive(TS))]
11315pub struct JSONArray {
11316    #[serde(default)]
11317    pub expressions: Vec<Expression>,
11318    #[serde(default)]
11319    pub null_handling: Option<Box<Expression>>,
11320    #[serde(default)]
11321    pub return_type: Option<Box<Expression>>,
11322    #[serde(default)]
11323    pub strict: Option<Box<Expression>>,
11324}
11325
11326/// JSONArrayAgg
11327#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11328#[cfg_attr(feature = "bindings", derive(TS))]
11329pub struct JSONArrayAgg {
11330    pub this: Box<Expression>,
11331    #[serde(default)]
11332    pub order: Option<Box<Expression>>,
11333    #[serde(default)]
11334    pub null_handling: Option<Box<Expression>>,
11335    #[serde(default)]
11336    pub return_type: Option<Box<Expression>>,
11337    #[serde(default)]
11338    pub strict: Option<Box<Expression>>,
11339}
11340
11341/// JSONExists
11342#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11343#[cfg_attr(feature = "bindings", derive(TS))]
11344pub struct JSONExists {
11345    pub this: Box<Expression>,
11346    #[serde(default)]
11347    pub path: Option<Box<Expression>>,
11348    #[serde(default)]
11349    pub passing: Option<Box<Expression>>,
11350    #[serde(default)]
11351    pub on_condition: Option<Box<Expression>>,
11352    #[serde(default)]
11353    pub from_dcolonqmark: Option<Box<Expression>>,
11354}
11355
11356/// JSONColumnDef
11357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11358#[cfg_attr(feature = "bindings", derive(TS))]
11359pub struct JSONColumnDef {
11360    #[serde(default)]
11361    pub this: Option<Box<Expression>>,
11362    #[serde(default)]
11363    pub kind: Option<String>,
11364    #[serde(default)]
11365    pub path: Option<Box<Expression>>,
11366    #[serde(default)]
11367    pub nested_schema: Option<Box<Expression>>,
11368    #[serde(default)]
11369    pub ordinality: Option<Box<Expression>>,
11370}
11371
11372/// JSONSchema
11373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11374#[cfg_attr(feature = "bindings", derive(TS))]
11375pub struct JSONSchema {
11376    #[serde(default)]
11377    pub expressions: Vec<Expression>,
11378}
11379
11380/// JSONSet
11381#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11382#[cfg_attr(feature = "bindings", derive(TS))]
11383pub struct JSONSet {
11384    pub this: Box<Expression>,
11385    #[serde(default)]
11386    pub expressions: Vec<Expression>,
11387}
11388
11389/// JSONStripNulls
11390#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11391#[cfg_attr(feature = "bindings", derive(TS))]
11392pub struct JSONStripNulls {
11393    pub this: Box<Expression>,
11394    #[serde(default)]
11395    pub expression: Option<Box<Expression>>,
11396    #[serde(default)]
11397    pub include_arrays: Option<Box<Expression>>,
11398    #[serde(default)]
11399    pub remove_empty: Option<Box<Expression>>,
11400}
11401
11402/// JSONValue
11403#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11404#[cfg_attr(feature = "bindings", derive(TS))]
11405pub struct JSONValue {
11406    pub this: Box<Expression>,
11407    #[serde(default)]
11408    pub path: Option<Box<Expression>>,
11409    #[serde(default)]
11410    pub returning: Option<Box<Expression>>,
11411    #[serde(default)]
11412    pub on_condition: Option<Box<Expression>>,
11413}
11414
11415/// JSONValueArray
11416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11417#[cfg_attr(feature = "bindings", derive(TS))]
11418pub struct JSONValueArray {
11419    pub this: Box<Expression>,
11420    #[serde(default)]
11421    pub expression: Option<Box<Expression>>,
11422}
11423
11424/// JSONRemove
11425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11426#[cfg_attr(feature = "bindings", derive(TS))]
11427pub struct JSONRemove {
11428    pub this: Box<Expression>,
11429    #[serde(default)]
11430    pub expressions: Vec<Expression>,
11431}
11432
11433/// JSONTable
11434#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11435#[cfg_attr(feature = "bindings", derive(TS))]
11436pub struct JSONTable {
11437    pub this: Box<Expression>,
11438    #[serde(default)]
11439    pub schema: Option<Box<Expression>>,
11440    #[serde(default)]
11441    pub path: Option<Box<Expression>>,
11442    #[serde(default)]
11443    pub error_handling: Option<Box<Expression>>,
11444    #[serde(default)]
11445    pub empty_handling: Option<Box<Expression>>,
11446}
11447
11448/// JSONType
11449#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11450#[cfg_attr(feature = "bindings", derive(TS))]
11451pub struct JSONType {
11452    pub this: Box<Expression>,
11453    #[serde(default)]
11454    pub expression: Option<Box<Expression>>,
11455}
11456
11457/// ObjectInsert
11458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11459#[cfg_attr(feature = "bindings", derive(TS))]
11460pub struct ObjectInsert {
11461    pub this: Box<Expression>,
11462    #[serde(default)]
11463    pub key: Option<Box<Expression>>,
11464    #[serde(default)]
11465    pub value: Option<Box<Expression>>,
11466    #[serde(default)]
11467    pub update_flag: Option<Box<Expression>>,
11468}
11469
11470/// OpenJSONColumnDef
11471#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11472#[cfg_attr(feature = "bindings", derive(TS))]
11473pub struct OpenJSONColumnDef {
11474    pub this: Box<Expression>,
11475    pub kind: String,
11476    #[serde(default)]
11477    pub path: Option<Box<Expression>>,
11478    #[serde(default)]
11479    pub as_json: Option<Box<Expression>>,
11480    /// The parsed data type for proper generation
11481    #[serde(default, skip_serializing_if = "Option::is_none")]
11482    pub data_type: Option<DataType>,
11483}
11484
11485/// OpenJSON
11486#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11487#[cfg_attr(feature = "bindings", derive(TS))]
11488pub struct OpenJSON {
11489    pub this: Box<Expression>,
11490    #[serde(default)]
11491    pub path: Option<Box<Expression>>,
11492    #[serde(default)]
11493    pub expressions: Vec<Expression>,
11494}
11495
11496/// JSONBExists
11497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11498#[cfg_attr(feature = "bindings", derive(TS))]
11499pub struct JSONBExists {
11500    pub this: Box<Expression>,
11501    #[serde(default)]
11502    pub path: Option<Box<Expression>>,
11503}
11504
11505/// JSONCast
11506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11507#[cfg_attr(feature = "bindings", derive(TS))]
11508pub struct JSONCast {
11509    pub this: Box<Expression>,
11510    pub to: DataType,
11511}
11512
11513/// JSONExtract
11514#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11515#[cfg_attr(feature = "bindings", derive(TS))]
11516pub struct JSONExtract {
11517    pub this: Box<Expression>,
11518    pub expression: Box<Expression>,
11519    #[serde(default)]
11520    pub only_json_types: Option<Box<Expression>>,
11521    #[serde(default)]
11522    pub expressions: Vec<Expression>,
11523    #[serde(default)]
11524    pub variant_extract: Option<Box<Expression>>,
11525    #[serde(default)]
11526    pub json_query: Option<Box<Expression>>,
11527    #[serde(default)]
11528    pub option: Option<Box<Expression>>,
11529    #[serde(default)]
11530    pub quote: Option<Box<Expression>>,
11531    #[serde(default)]
11532    pub on_condition: Option<Box<Expression>>,
11533    #[serde(default)]
11534    pub requires_json: Option<Box<Expression>>,
11535}
11536
11537/// JSONExtractQuote
11538#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11539#[cfg_attr(feature = "bindings", derive(TS))]
11540pub struct JSONExtractQuote {
11541    #[serde(default)]
11542    pub option: Option<Box<Expression>>,
11543    #[serde(default)]
11544    pub scalar: Option<Box<Expression>>,
11545}
11546
11547/// JSONExtractArray
11548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11549#[cfg_attr(feature = "bindings", derive(TS))]
11550pub struct JSONExtractArray {
11551    pub this: Box<Expression>,
11552    #[serde(default)]
11553    pub expression: Option<Box<Expression>>,
11554}
11555
11556/// JSONExtractScalar
11557#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11558#[cfg_attr(feature = "bindings", derive(TS))]
11559pub struct JSONExtractScalar {
11560    pub this: Box<Expression>,
11561    pub expression: Box<Expression>,
11562    #[serde(default)]
11563    pub only_json_types: Option<Box<Expression>>,
11564    #[serde(default)]
11565    pub expressions: Vec<Expression>,
11566    #[serde(default)]
11567    pub json_type: Option<Box<Expression>>,
11568    #[serde(default)]
11569    pub scalar_only: Option<Box<Expression>>,
11570}
11571
11572/// JSONBExtractScalar
11573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11574#[cfg_attr(feature = "bindings", derive(TS))]
11575pub struct JSONBExtractScalar {
11576    pub this: Box<Expression>,
11577    pub expression: Box<Expression>,
11578    #[serde(default)]
11579    pub json_type: Option<Box<Expression>>,
11580}
11581
11582/// JSONFormat
11583#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11584#[cfg_attr(feature = "bindings", derive(TS))]
11585pub struct JSONFormat {
11586    #[serde(default)]
11587    pub this: Option<Box<Expression>>,
11588    #[serde(default)]
11589    pub options: Vec<Expression>,
11590    #[serde(default)]
11591    pub is_json: Option<Box<Expression>>,
11592    #[serde(default)]
11593    pub to_json: Option<Box<Expression>>,
11594}
11595
11596/// JSONArrayAppend
11597#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11598#[cfg_attr(feature = "bindings", derive(TS))]
11599pub struct JSONArrayAppend {
11600    pub this: Box<Expression>,
11601    #[serde(default)]
11602    pub expressions: Vec<Expression>,
11603}
11604
11605/// JSONArrayContains
11606#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11607#[cfg_attr(feature = "bindings", derive(TS))]
11608pub struct JSONArrayContains {
11609    pub this: Box<Expression>,
11610    pub expression: Box<Expression>,
11611    #[serde(default)]
11612    pub json_type: Option<Box<Expression>>,
11613}
11614
11615/// JSONArrayInsert
11616#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11617#[cfg_attr(feature = "bindings", derive(TS))]
11618pub struct JSONArrayInsert {
11619    pub this: Box<Expression>,
11620    #[serde(default)]
11621    pub expressions: Vec<Expression>,
11622}
11623
11624/// ParseJSON
11625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11626#[cfg_attr(feature = "bindings", derive(TS))]
11627pub struct ParseJSON {
11628    pub this: Box<Expression>,
11629    #[serde(default)]
11630    pub expression: Option<Box<Expression>>,
11631    #[serde(default)]
11632    pub safe: Option<Box<Expression>>,
11633}
11634
11635/// ParseUrl
11636#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11637#[cfg_attr(feature = "bindings", derive(TS))]
11638pub struct ParseUrl {
11639    pub this: Box<Expression>,
11640    #[serde(default)]
11641    pub part_to_extract: Option<Box<Expression>>,
11642    #[serde(default)]
11643    pub key: Option<Box<Expression>>,
11644    #[serde(default)]
11645    pub permissive: Option<Box<Expression>>,
11646}
11647
11648/// ParseIp
11649#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11650#[cfg_attr(feature = "bindings", derive(TS))]
11651pub struct ParseIp {
11652    pub this: Box<Expression>,
11653    #[serde(default)]
11654    pub type_: Option<Box<Expression>>,
11655    #[serde(default)]
11656    pub permissive: Option<Box<Expression>>,
11657}
11658
11659/// ParseTime
11660#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11661#[cfg_attr(feature = "bindings", derive(TS))]
11662pub struct ParseTime {
11663    pub this: Box<Expression>,
11664    pub format: String,
11665}
11666
11667/// ParseDatetime
11668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11669#[cfg_attr(feature = "bindings", derive(TS))]
11670pub struct ParseDatetime {
11671    pub this: Box<Expression>,
11672    #[serde(default)]
11673    pub format: Option<String>,
11674    #[serde(default)]
11675    pub zone: Option<Box<Expression>>,
11676}
11677
11678/// Map
11679#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11680#[cfg_attr(feature = "bindings", derive(TS))]
11681pub struct Map {
11682    #[serde(default)]
11683    pub keys: Vec<Expression>,
11684    #[serde(default)]
11685    pub values: Vec<Expression>,
11686}
11687
11688/// MapCat
11689#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11690#[cfg_attr(feature = "bindings", derive(TS))]
11691pub struct MapCat {
11692    pub this: Box<Expression>,
11693    pub expression: Box<Expression>,
11694}
11695
11696/// MapDelete
11697#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11698#[cfg_attr(feature = "bindings", derive(TS))]
11699pub struct MapDelete {
11700    pub this: Box<Expression>,
11701    #[serde(default)]
11702    pub expressions: Vec<Expression>,
11703}
11704
11705/// MapInsert
11706#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11707#[cfg_attr(feature = "bindings", derive(TS))]
11708pub struct MapInsert {
11709    pub this: Box<Expression>,
11710    #[serde(default)]
11711    pub key: Option<Box<Expression>>,
11712    #[serde(default)]
11713    pub value: Option<Box<Expression>>,
11714    #[serde(default)]
11715    pub update_flag: Option<Box<Expression>>,
11716}
11717
11718/// MapPick
11719#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11720#[cfg_attr(feature = "bindings", derive(TS))]
11721pub struct MapPick {
11722    pub this: Box<Expression>,
11723    #[serde(default)]
11724    pub expressions: Vec<Expression>,
11725}
11726
11727/// ScopeResolution
11728#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11729#[cfg_attr(feature = "bindings", derive(TS))]
11730pub struct ScopeResolution {
11731    #[serde(default)]
11732    pub this: Option<Box<Expression>>,
11733    pub expression: Box<Expression>,
11734}
11735
11736/// Slice
11737#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11738#[cfg_attr(feature = "bindings", derive(TS))]
11739pub struct Slice {
11740    #[serde(default)]
11741    pub this: Option<Box<Expression>>,
11742    #[serde(default)]
11743    pub expression: Option<Box<Expression>>,
11744    #[serde(default)]
11745    pub step: Option<Box<Expression>>,
11746}
11747
11748/// VarMap
11749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11750#[cfg_attr(feature = "bindings", derive(TS))]
11751pub struct VarMap {
11752    #[serde(default)]
11753    pub keys: Vec<Expression>,
11754    #[serde(default)]
11755    pub values: Vec<Expression>,
11756}
11757
11758/// MatchAgainst
11759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11760#[cfg_attr(feature = "bindings", derive(TS))]
11761pub struct MatchAgainst {
11762    pub this: Box<Expression>,
11763    #[serde(default)]
11764    pub expressions: Vec<Expression>,
11765    #[serde(default)]
11766    pub modifier: Option<Box<Expression>>,
11767}
11768
11769/// MD5Digest
11770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11771#[cfg_attr(feature = "bindings", derive(TS))]
11772pub struct MD5Digest {
11773    pub this: Box<Expression>,
11774    #[serde(default)]
11775    pub expressions: Vec<Expression>,
11776}
11777
11778/// Monthname
11779#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11780#[cfg_attr(feature = "bindings", derive(TS))]
11781pub struct Monthname {
11782    pub this: Box<Expression>,
11783    #[serde(default)]
11784    pub abbreviated: Option<Box<Expression>>,
11785}
11786
11787/// Ntile
11788#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11789#[cfg_attr(feature = "bindings", derive(TS))]
11790pub struct Ntile {
11791    #[serde(default)]
11792    pub this: Option<Box<Expression>>,
11793}
11794
11795/// Normalize
11796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11797#[cfg_attr(feature = "bindings", derive(TS))]
11798pub struct Normalize {
11799    pub this: Box<Expression>,
11800    #[serde(default)]
11801    pub form: Option<Box<Expression>>,
11802    #[serde(default)]
11803    pub is_casefold: Option<Box<Expression>>,
11804}
11805
11806/// Normal
11807#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11808#[cfg_attr(feature = "bindings", derive(TS))]
11809pub struct Normal {
11810    pub this: Box<Expression>,
11811    #[serde(default)]
11812    pub stddev: Option<Box<Expression>>,
11813    #[serde(default)]
11814    pub gen: Option<Box<Expression>>,
11815}
11816
11817/// Predict
11818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11819#[cfg_attr(feature = "bindings", derive(TS))]
11820pub struct Predict {
11821    pub this: Box<Expression>,
11822    pub expression: Box<Expression>,
11823    #[serde(default)]
11824    pub params_struct: Option<Box<Expression>>,
11825}
11826
11827/// MLTranslate
11828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11829#[cfg_attr(feature = "bindings", derive(TS))]
11830pub struct MLTranslate {
11831    pub this: Box<Expression>,
11832    pub expression: Box<Expression>,
11833    #[serde(default)]
11834    pub params_struct: Option<Box<Expression>>,
11835}
11836
11837/// FeaturesAtTime
11838#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11839#[cfg_attr(feature = "bindings", derive(TS))]
11840pub struct FeaturesAtTime {
11841    pub this: Box<Expression>,
11842    #[serde(default)]
11843    pub time: Option<Box<Expression>>,
11844    #[serde(default)]
11845    pub num_rows: Option<Box<Expression>>,
11846    #[serde(default)]
11847    pub ignore_feature_nulls: Option<Box<Expression>>,
11848}
11849
11850/// GenerateEmbedding
11851#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11852#[cfg_attr(feature = "bindings", derive(TS))]
11853pub struct GenerateEmbedding {
11854    pub this: Box<Expression>,
11855    pub expression: Box<Expression>,
11856    #[serde(default)]
11857    pub params_struct: Option<Box<Expression>>,
11858    #[serde(default)]
11859    pub is_text: Option<Box<Expression>>,
11860}
11861
11862/// MLForecast
11863#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11864#[cfg_attr(feature = "bindings", derive(TS))]
11865pub struct MLForecast {
11866    pub this: Box<Expression>,
11867    #[serde(default)]
11868    pub expression: Option<Box<Expression>>,
11869    #[serde(default)]
11870    pub params_struct: Option<Box<Expression>>,
11871}
11872
11873/// ModelAttribute
11874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11875#[cfg_attr(feature = "bindings", derive(TS))]
11876pub struct ModelAttribute {
11877    pub this: Box<Expression>,
11878    pub expression: Box<Expression>,
11879}
11880
11881/// VectorSearch
11882#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11883#[cfg_attr(feature = "bindings", derive(TS))]
11884pub struct VectorSearch {
11885    pub this: Box<Expression>,
11886    #[serde(default)]
11887    pub column_to_search: Option<Box<Expression>>,
11888    #[serde(default)]
11889    pub query_table: Option<Box<Expression>>,
11890    #[serde(default)]
11891    pub query_column_to_search: Option<Box<Expression>>,
11892    #[serde(default)]
11893    pub top_k: Option<Box<Expression>>,
11894    #[serde(default)]
11895    pub distance_type: Option<Box<Expression>>,
11896    #[serde(default)]
11897    pub options: Vec<Expression>,
11898}
11899
11900/// Quantile
11901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11902#[cfg_attr(feature = "bindings", derive(TS))]
11903pub struct Quantile {
11904    pub this: Box<Expression>,
11905    #[serde(default)]
11906    pub quantile: Option<Box<Expression>>,
11907}
11908
11909/// ApproxQuantile
11910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11911#[cfg_attr(feature = "bindings", derive(TS))]
11912pub struct ApproxQuantile {
11913    pub this: Box<Expression>,
11914    #[serde(default)]
11915    pub quantile: Option<Box<Expression>>,
11916    #[serde(default)]
11917    pub accuracy: Option<Box<Expression>>,
11918    #[serde(default)]
11919    pub weight: Option<Box<Expression>>,
11920    #[serde(default)]
11921    pub error_tolerance: Option<Box<Expression>>,
11922}
11923
11924/// ApproxPercentileEstimate
11925#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11926#[cfg_attr(feature = "bindings", derive(TS))]
11927pub struct ApproxPercentileEstimate {
11928    pub this: Box<Expression>,
11929    #[serde(default)]
11930    pub percentile: Option<Box<Expression>>,
11931}
11932
11933/// Randn
11934#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11935#[cfg_attr(feature = "bindings", derive(TS))]
11936pub struct Randn {
11937    #[serde(default)]
11938    pub this: Option<Box<Expression>>,
11939}
11940
11941/// Randstr
11942#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11943#[cfg_attr(feature = "bindings", derive(TS))]
11944pub struct Randstr {
11945    pub this: Box<Expression>,
11946    #[serde(default)]
11947    pub generator: Option<Box<Expression>>,
11948}
11949
11950/// RangeN
11951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11952#[cfg_attr(feature = "bindings", derive(TS))]
11953pub struct RangeN {
11954    pub this: Box<Expression>,
11955    #[serde(default)]
11956    pub expressions: Vec<Expression>,
11957    #[serde(default)]
11958    pub each: Option<Box<Expression>>,
11959}
11960
11961/// RangeBucket
11962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11963#[cfg_attr(feature = "bindings", derive(TS))]
11964pub struct RangeBucket {
11965    pub this: Box<Expression>,
11966    pub expression: Box<Expression>,
11967}
11968
11969/// ReadCSV
11970#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11971#[cfg_attr(feature = "bindings", derive(TS))]
11972pub struct ReadCSV {
11973    pub this: Box<Expression>,
11974    #[serde(default)]
11975    pub expressions: Vec<Expression>,
11976}
11977
11978/// ReadParquet
11979#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11980#[cfg_attr(feature = "bindings", derive(TS))]
11981pub struct ReadParquet {
11982    #[serde(default)]
11983    pub expressions: Vec<Expression>,
11984}
11985
11986/// Reduce
11987#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11988#[cfg_attr(feature = "bindings", derive(TS))]
11989pub struct Reduce {
11990    pub this: Box<Expression>,
11991    #[serde(default)]
11992    pub initial: Option<Box<Expression>>,
11993    #[serde(default)]
11994    pub merge: Option<Box<Expression>>,
11995    #[serde(default)]
11996    pub finish: Option<Box<Expression>>,
11997}
11998
11999/// RegexpExtractAll
12000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12001#[cfg_attr(feature = "bindings", derive(TS))]
12002pub struct RegexpExtractAll {
12003    pub this: Box<Expression>,
12004    pub expression: Box<Expression>,
12005    #[serde(default)]
12006    pub group: Option<Box<Expression>>,
12007    #[serde(default)]
12008    pub parameters: Option<Box<Expression>>,
12009    #[serde(default)]
12010    pub position: Option<Box<Expression>>,
12011    #[serde(default)]
12012    pub occurrence: Option<Box<Expression>>,
12013}
12014
12015/// RegexpILike
12016#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12017#[cfg_attr(feature = "bindings", derive(TS))]
12018pub struct RegexpILike {
12019    pub this: Box<Expression>,
12020    pub expression: Box<Expression>,
12021    #[serde(default)]
12022    pub flag: Option<Box<Expression>>,
12023}
12024
12025/// RegexpFullMatch
12026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12027#[cfg_attr(feature = "bindings", derive(TS))]
12028pub struct RegexpFullMatch {
12029    pub this: Box<Expression>,
12030    pub expression: Box<Expression>,
12031    #[serde(default)]
12032    pub options: Vec<Expression>,
12033}
12034
12035/// RegexpInstr
12036#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12037#[cfg_attr(feature = "bindings", derive(TS))]
12038pub struct RegexpInstr {
12039    pub this: Box<Expression>,
12040    pub expression: Box<Expression>,
12041    #[serde(default)]
12042    pub position: Option<Box<Expression>>,
12043    #[serde(default)]
12044    pub occurrence: Option<Box<Expression>>,
12045    #[serde(default)]
12046    pub option: Option<Box<Expression>>,
12047    #[serde(default)]
12048    pub parameters: Option<Box<Expression>>,
12049    #[serde(default)]
12050    pub group: Option<Box<Expression>>,
12051}
12052
12053/// RegexpSplit
12054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12055#[cfg_attr(feature = "bindings", derive(TS))]
12056pub struct RegexpSplit {
12057    pub this: Box<Expression>,
12058    pub expression: Box<Expression>,
12059    #[serde(default)]
12060    pub limit: Option<Box<Expression>>,
12061}
12062
12063/// RegexpCount
12064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12065#[cfg_attr(feature = "bindings", derive(TS))]
12066pub struct RegexpCount {
12067    pub this: Box<Expression>,
12068    pub expression: Box<Expression>,
12069    #[serde(default)]
12070    pub position: Option<Box<Expression>>,
12071    #[serde(default)]
12072    pub parameters: Option<Box<Expression>>,
12073}
12074
12075/// RegrValx
12076#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12077#[cfg_attr(feature = "bindings", derive(TS))]
12078pub struct RegrValx {
12079    pub this: Box<Expression>,
12080    pub expression: Box<Expression>,
12081}
12082
12083/// RegrValy
12084#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12085#[cfg_attr(feature = "bindings", derive(TS))]
12086pub struct RegrValy {
12087    pub this: Box<Expression>,
12088    pub expression: Box<Expression>,
12089}
12090
12091/// RegrAvgy
12092#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12093#[cfg_attr(feature = "bindings", derive(TS))]
12094pub struct RegrAvgy {
12095    pub this: Box<Expression>,
12096    pub expression: Box<Expression>,
12097}
12098
12099/// RegrAvgx
12100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12101#[cfg_attr(feature = "bindings", derive(TS))]
12102pub struct RegrAvgx {
12103    pub this: Box<Expression>,
12104    pub expression: Box<Expression>,
12105}
12106
12107/// RegrCount
12108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12109#[cfg_attr(feature = "bindings", derive(TS))]
12110pub struct RegrCount {
12111    pub this: Box<Expression>,
12112    pub expression: Box<Expression>,
12113}
12114
12115/// RegrIntercept
12116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12117#[cfg_attr(feature = "bindings", derive(TS))]
12118pub struct RegrIntercept {
12119    pub this: Box<Expression>,
12120    pub expression: Box<Expression>,
12121}
12122
12123/// RegrR2
12124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12125#[cfg_attr(feature = "bindings", derive(TS))]
12126pub struct RegrR2 {
12127    pub this: Box<Expression>,
12128    pub expression: Box<Expression>,
12129}
12130
12131/// RegrSxx
12132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12133#[cfg_attr(feature = "bindings", derive(TS))]
12134pub struct RegrSxx {
12135    pub this: Box<Expression>,
12136    pub expression: Box<Expression>,
12137}
12138
12139/// RegrSxy
12140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12141#[cfg_attr(feature = "bindings", derive(TS))]
12142pub struct RegrSxy {
12143    pub this: Box<Expression>,
12144    pub expression: Box<Expression>,
12145}
12146
12147/// RegrSyy
12148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12149#[cfg_attr(feature = "bindings", derive(TS))]
12150pub struct RegrSyy {
12151    pub this: Box<Expression>,
12152    pub expression: Box<Expression>,
12153}
12154
12155/// RegrSlope
12156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12157#[cfg_attr(feature = "bindings", derive(TS))]
12158pub struct RegrSlope {
12159    pub this: Box<Expression>,
12160    pub expression: Box<Expression>,
12161}
12162
12163/// SafeAdd
12164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12165#[cfg_attr(feature = "bindings", derive(TS))]
12166pub struct SafeAdd {
12167    pub this: Box<Expression>,
12168    pub expression: Box<Expression>,
12169}
12170
12171/// SafeDivide
12172#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12173#[cfg_attr(feature = "bindings", derive(TS))]
12174pub struct SafeDivide {
12175    pub this: Box<Expression>,
12176    pub expression: Box<Expression>,
12177}
12178
12179/// SafeMultiply
12180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12181#[cfg_attr(feature = "bindings", derive(TS))]
12182pub struct SafeMultiply {
12183    pub this: Box<Expression>,
12184    pub expression: Box<Expression>,
12185}
12186
12187/// SafeSubtract
12188#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12189#[cfg_attr(feature = "bindings", derive(TS))]
12190pub struct SafeSubtract {
12191    pub this: Box<Expression>,
12192    pub expression: Box<Expression>,
12193}
12194
12195/// SHA2
12196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12197#[cfg_attr(feature = "bindings", derive(TS))]
12198pub struct SHA2 {
12199    pub this: Box<Expression>,
12200    #[serde(default)]
12201    pub length: Option<i64>,
12202}
12203
12204/// SHA2Digest
12205#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12206#[cfg_attr(feature = "bindings", derive(TS))]
12207pub struct SHA2Digest {
12208    pub this: Box<Expression>,
12209    #[serde(default)]
12210    pub length: Option<i64>,
12211}
12212
12213/// SortArray
12214#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12215#[cfg_attr(feature = "bindings", derive(TS))]
12216pub struct SortArray {
12217    pub this: Box<Expression>,
12218    #[serde(default)]
12219    pub asc: Option<Box<Expression>>,
12220    #[serde(default)]
12221    pub nulls_first: Option<Box<Expression>>,
12222}
12223
12224/// SplitPart
12225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12226#[cfg_attr(feature = "bindings", derive(TS))]
12227pub struct SplitPart {
12228    pub this: Box<Expression>,
12229    #[serde(default)]
12230    pub delimiter: Option<Box<Expression>>,
12231    #[serde(default)]
12232    pub part_index: Option<Box<Expression>>,
12233}
12234
12235/// SUBSTRING_INDEX(str, delim, count)
12236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12237#[cfg_attr(feature = "bindings", derive(TS))]
12238pub struct SubstringIndex {
12239    pub this: Box<Expression>,
12240    #[serde(default)]
12241    pub delimiter: Option<Box<Expression>>,
12242    #[serde(default)]
12243    pub count: Option<Box<Expression>>,
12244}
12245
12246/// StandardHash
12247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12248#[cfg_attr(feature = "bindings", derive(TS))]
12249pub struct StandardHash {
12250    pub this: Box<Expression>,
12251    #[serde(default)]
12252    pub expression: Option<Box<Expression>>,
12253}
12254
12255/// StrPosition
12256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12257#[cfg_attr(feature = "bindings", derive(TS))]
12258pub struct StrPosition {
12259    pub this: Box<Expression>,
12260    #[serde(default)]
12261    pub substr: Option<Box<Expression>>,
12262    #[serde(default)]
12263    pub position: Option<Box<Expression>>,
12264    #[serde(default)]
12265    pub occurrence: Option<Box<Expression>>,
12266}
12267
12268/// Search
12269#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12270#[cfg_attr(feature = "bindings", derive(TS))]
12271pub struct Search {
12272    pub this: Box<Expression>,
12273    pub expression: Box<Expression>,
12274    #[serde(default)]
12275    pub json_scope: Option<Box<Expression>>,
12276    #[serde(default)]
12277    pub analyzer: Option<Box<Expression>>,
12278    #[serde(default)]
12279    pub analyzer_options: Option<Box<Expression>>,
12280    #[serde(default)]
12281    pub search_mode: Option<Box<Expression>>,
12282}
12283
12284/// SearchIp
12285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12286#[cfg_attr(feature = "bindings", derive(TS))]
12287pub struct SearchIp {
12288    pub this: Box<Expression>,
12289    pub expression: Box<Expression>,
12290}
12291
12292/// StrToDate
12293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12294#[cfg_attr(feature = "bindings", derive(TS))]
12295pub struct StrToDate {
12296    pub this: Box<Expression>,
12297    #[serde(default)]
12298    pub format: Option<String>,
12299    #[serde(default)]
12300    pub safe: Option<Box<Expression>>,
12301}
12302
12303/// StrToTime
12304#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12305#[cfg_attr(feature = "bindings", derive(TS))]
12306pub struct StrToTime {
12307    pub this: Box<Expression>,
12308    pub format: String,
12309    #[serde(default)]
12310    pub zone: Option<Box<Expression>>,
12311    #[serde(default)]
12312    pub safe: Option<Box<Expression>>,
12313    #[serde(default)]
12314    pub target_type: Option<Box<Expression>>,
12315}
12316
12317/// StrToUnix
12318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12319#[cfg_attr(feature = "bindings", derive(TS))]
12320pub struct StrToUnix {
12321    #[serde(default)]
12322    pub this: Option<Box<Expression>>,
12323    #[serde(default)]
12324    pub format: Option<String>,
12325}
12326
12327/// StrToMap
12328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12329#[cfg_attr(feature = "bindings", derive(TS))]
12330pub struct StrToMap {
12331    pub this: Box<Expression>,
12332    #[serde(default)]
12333    pub pair_delim: Option<Box<Expression>>,
12334    #[serde(default)]
12335    pub key_value_delim: Option<Box<Expression>>,
12336    #[serde(default)]
12337    pub duplicate_resolution_callback: Option<Box<Expression>>,
12338}
12339
12340/// NumberToStr
12341#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12342#[cfg_attr(feature = "bindings", derive(TS))]
12343pub struct NumberToStr {
12344    pub this: Box<Expression>,
12345    pub format: String,
12346    #[serde(default)]
12347    pub culture: Option<Box<Expression>>,
12348}
12349
12350/// FromBase
12351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12352#[cfg_attr(feature = "bindings", derive(TS))]
12353pub struct FromBase {
12354    pub this: Box<Expression>,
12355    pub expression: Box<Expression>,
12356}
12357
12358/// Stuff
12359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12360#[cfg_attr(feature = "bindings", derive(TS))]
12361pub struct Stuff {
12362    pub this: Box<Expression>,
12363    #[serde(default)]
12364    pub start: Option<Box<Expression>>,
12365    #[serde(default)]
12366    pub length: Option<i64>,
12367    pub expression: Box<Expression>,
12368}
12369
12370/// TimeToStr
12371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12372#[cfg_attr(feature = "bindings", derive(TS))]
12373pub struct TimeToStr {
12374    pub this: Box<Expression>,
12375    pub format: String,
12376    #[serde(default)]
12377    pub culture: Option<Box<Expression>>,
12378    #[serde(default)]
12379    pub zone: Option<Box<Expression>>,
12380}
12381
12382/// TimeStrToTime
12383#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12384#[cfg_attr(feature = "bindings", derive(TS))]
12385pub struct TimeStrToTime {
12386    pub this: Box<Expression>,
12387    #[serde(default)]
12388    pub zone: Option<Box<Expression>>,
12389}
12390
12391/// TsOrDsAdd
12392#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12393#[cfg_attr(feature = "bindings", derive(TS))]
12394pub struct TsOrDsAdd {
12395    pub this: Box<Expression>,
12396    pub expression: Box<Expression>,
12397    #[serde(default)]
12398    pub unit: Option<String>,
12399    #[serde(default)]
12400    pub return_type: Option<Box<Expression>>,
12401}
12402
12403/// TsOrDsDiff
12404#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12405#[cfg_attr(feature = "bindings", derive(TS))]
12406pub struct TsOrDsDiff {
12407    pub this: Box<Expression>,
12408    pub expression: Box<Expression>,
12409    #[serde(default)]
12410    pub unit: Option<String>,
12411}
12412
12413/// TsOrDsToDate
12414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12415#[cfg_attr(feature = "bindings", derive(TS))]
12416pub struct TsOrDsToDate {
12417    pub this: Box<Expression>,
12418    #[serde(default)]
12419    pub format: Option<String>,
12420    #[serde(default)]
12421    pub safe: Option<Box<Expression>>,
12422}
12423
12424/// TsOrDsToTime
12425#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12426#[cfg_attr(feature = "bindings", derive(TS))]
12427pub struct TsOrDsToTime {
12428    pub this: Box<Expression>,
12429    #[serde(default)]
12430    pub format: Option<String>,
12431    #[serde(default)]
12432    pub safe: Option<Box<Expression>>,
12433}
12434
12435/// Unhex
12436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12437#[cfg_attr(feature = "bindings", derive(TS))]
12438pub struct Unhex {
12439    pub this: Box<Expression>,
12440    #[serde(default)]
12441    pub expression: Option<Box<Expression>>,
12442}
12443
12444/// Uniform
12445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12446#[cfg_attr(feature = "bindings", derive(TS))]
12447pub struct Uniform {
12448    pub this: Box<Expression>,
12449    pub expression: Box<Expression>,
12450    #[serde(default)]
12451    pub gen: Option<Box<Expression>>,
12452    #[serde(default)]
12453    pub seed: Option<Box<Expression>>,
12454}
12455
12456/// UnixToStr
12457#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12458#[cfg_attr(feature = "bindings", derive(TS))]
12459pub struct UnixToStr {
12460    pub this: Box<Expression>,
12461    #[serde(default)]
12462    pub format: Option<String>,
12463}
12464
12465/// UnixToTime
12466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12467#[cfg_attr(feature = "bindings", derive(TS))]
12468pub struct UnixToTime {
12469    pub this: Box<Expression>,
12470    #[serde(default)]
12471    pub scale: Option<i64>,
12472    #[serde(default)]
12473    pub zone: Option<Box<Expression>>,
12474    #[serde(default)]
12475    pub hours: Option<Box<Expression>>,
12476    #[serde(default)]
12477    pub minutes: Option<Box<Expression>>,
12478    #[serde(default)]
12479    pub format: Option<String>,
12480    #[serde(default)]
12481    pub target_type: Option<Box<Expression>>,
12482}
12483
12484/// Uuid
12485#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12486#[cfg_attr(feature = "bindings", derive(TS))]
12487pub struct Uuid {
12488    #[serde(default)]
12489    pub this: Option<Box<Expression>>,
12490    #[serde(default)]
12491    pub name: Option<String>,
12492    #[serde(default)]
12493    pub is_string: Option<Box<Expression>>,
12494}
12495
12496/// TimestampFromParts
12497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12498#[cfg_attr(feature = "bindings", derive(TS))]
12499pub struct TimestampFromParts {
12500    #[serde(default)]
12501    pub zone: Option<Box<Expression>>,
12502    #[serde(default)]
12503    pub milli: Option<Box<Expression>>,
12504    #[serde(default)]
12505    pub this: Option<Box<Expression>>,
12506    #[serde(default)]
12507    pub expression: Option<Box<Expression>>,
12508}
12509
12510/// TimestampTzFromParts
12511#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12512#[cfg_attr(feature = "bindings", derive(TS))]
12513pub struct TimestampTzFromParts {
12514    #[serde(default)]
12515    pub zone: Option<Box<Expression>>,
12516}
12517
12518/// Corr
12519#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12520#[cfg_attr(feature = "bindings", derive(TS))]
12521pub struct Corr {
12522    pub this: Box<Expression>,
12523    pub expression: Box<Expression>,
12524    #[serde(default)]
12525    pub null_on_zero_variance: Option<Box<Expression>>,
12526}
12527
12528/// WidthBucket
12529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12530#[cfg_attr(feature = "bindings", derive(TS))]
12531pub struct WidthBucket {
12532    pub this: Box<Expression>,
12533    #[serde(default)]
12534    pub min_value: Option<Box<Expression>>,
12535    #[serde(default)]
12536    pub max_value: Option<Box<Expression>>,
12537    #[serde(default)]
12538    pub num_buckets: Option<Box<Expression>>,
12539    #[serde(default)]
12540    pub threshold: Option<Box<Expression>>,
12541}
12542
12543/// CovarSamp
12544#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12545#[cfg_attr(feature = "bindings", derive(TS))]
12546pub struct CovarSamp {
12547    pub this: Box<Expression>,
12548    pub expression: Box<Expression>,
12549}
12550
12551/// CovarPop
12552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12553#[cfg_attr(feature = "bindings", derive(TS))]
12554pub struct CovarPop {
12555    pub this: Box<Expression>,
12556    pub expression: Box<Expression>,
12557}
12558
12559/// Week
12560#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12561#[cfg_attr(feature = "bindings", derive(TS))]
12562pub struct Week {
12563    pub this: Box<Expression>,
12564    #[serde(default)]
12565    pub mode: Option<Box<Expression>>,
12566}
12567
12568/// XMLElement
12569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12570#[cfg_attr(feature = "bindings", derive(TS))]
12571pub struct XMLElement {
12572    pub this: Box<Expression>,
12573    #[serde(default)]
12574    pub expressions: Vec<Expression>,
12575    #[serde(default)]
12576    pub evalname: Option<Box<Expression>>,
12577}
12578
12579/// XMLGet
12580#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12581#[cfg_attr(feature = "bindings", derive(TS))]
12582pub struct XMLGet {
12583    pub this: Box<Expression>,
12584    pub expression: Box<Expression>,
12585    #[serde(default)]
12586    pub instance: Option<Box<Expression>>,
12587}
12588
12589/// XMLTable
12590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12591#[cfg_attr(feature = "bindings", derive(TS))]
12592pub struct XMLTable {
12593    pub this: Box<Expression>,
12594    #[serde(default)]
12595    pub namespaces: Option<Box<Expression>>,
12596    #[serde(default)]
12597    pub passing: Option<Box<Expression>>,
12598    #[serde(default)]
12599    pub columns: Vec<Expression>,
12600    #[serde(default)]
12601    pub by_ref: Option<Box<Expression>>,
12602}
12603
12604/// XMLKeyValueOption
12605#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12606#[cfg_attr(feature = "bindings", derive(TS))]
12607pub struct XMLKeyValueOption {
12608    pub this: Box<Expression>,
12609    #[serde(default)]
12610    pub expression: Option<Box<Expression>>,
12611}
12612
12613/// Zipf
12614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12615#[cfg_attr(feature = "bindings", derive(TS))]
12616pub struct Zipf {
12617    pub this: Box<Expression>,
12618    #[serde(default)]
12619    pub elementcount: Option<Box<Expression>>,
12620    #[serde(default)]
12621    pub gen: Option<Box<Expression>>,
12622}
12623
12624/// Merge
12625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12626#[cfg_attr(feature = "bindings", derive(TS))]
12627pub struct Merge {
12628    pub this: Box<Expression>,
12629    pub using: Box<Expression>,
12630    #[serde(default)]
12631    pub on: Option<Box<Expression>>,
12632    #[serde(default)]
12633    pub using_cond: Option<Box<Expression>>,
12634    #[serde(default)]
12635    pub whens: Option<Box<Expression>>,
12636    #[serde(default)]
12637    pub with_: Option<Box<Expression>>,
12638    #[serde(default)]
12639    pub returning: Option<Box<Expression>>,
12640}
12641
12642/// When
12643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12644#[cfg_attr(feature = "bindings", derive(TS))]
12645pub struct When {
12646    #[serde(default)]
12647    pub matched: Option<Box<Expression>>,
12648    #[serde(default)]
12649    pub source: Option<Box<Expression>>,
12650    #[serde(default)]
12651    pub condition: Option<Box<Expression>>,
12652    pub then: Box<Expression>,
12653}
12654
12655/// Wraps around one or more WHEN [NOT] MATCHED [...] clauses.
12656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12657#[cfg_attr(feature = "bindings", derive(TS))]
12658pub struct Whens {
12659    #[serde(default)]
12660    pub expressions: Vec<Expression>,
12661}
12662
12663/// NextValueFor
12664#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12665#[cfg_attr(feature = "bindings", derive(TS))]
12666pub struct NextValueFor {
12667    pub this: Box<Expression>,
12668    #[serde(default)]
12669    pub order: Option<Box<Expression>>,
12670}
12671
12672#[cfg(test)]
12673mod tests {
12674    use super::*;
12675
12676    #[test]
12677    #[cfg(feature = "bindings")]
12678    fn export_typescript_types() {
12679        // This test exports TypeScript types to the generated directory
12680        // Run with: cargo test -p polyglot-sql --features bindings export_typescript_types
12681        Expression::export_all(&ts_rs::Config::default())
12682            .expect("Failed to export Expression types");
12683    }
12684
12685    #[test]
12686    fn test_simple_select_builder() {
12687        let select = Select::new()
12688            .column(Expression::star())
12689            .from(Expression::Table(TableRef::new("users")));
12690
12691        assert_eq!(select.expressions.len(), 1);
12692        assert!(select.from.is_some());
12693    }
12694
12695    #[test]
12696    fn test_expression_alias() {
12697        let expr = Expression::column("id").alias("user_id");
12698
12699        match expr {
12700            Expression::Alias(a) => {
12701                assert_eq!(a.alias.name, "user_id");
12702            }
12703            _ => panic!("Expected Alias"),
12704        }
12705    }
12706
12707    #[test]
12708    fn test_literal_creation() {
12709        let num = Expression::number(42);
12710        let str = Expression::string("hello");
12711
12712        match num {
12713            Expression::Literal(Literal::Number(n)) => assert_eq!(n, "42"),
12714            _ => panic!("Expected Number"),
12715        }
12716
12717        match str {
12718            Expression::Literal(Literal::String(s)) => assert_eq!(s, "hello"),
12719            _ => panic!("Expected String"),
12720        }
12721    }
12722
12723    #[test]
12724    fn test_expression_sql() {
12725        let expr = crate::parse_one("SELECT 1 + 2", crate::DialectType::Generic).unwrap();
12726        assert_eq!(expr.sql(), "SELECT 1 + 2");
12727    }
12728
12729    #[test]
12730    fn test_expression_sql_for() {
12731        let expr = crate::parse_one("SELECT IF(x > 0, 1, 0)", crate::DialectType::Generic).unwrap();
12732        let sql = expr.sql_for(crate::DialectType::Generic);
12733        // Generic mode normalizes IF() to CASE WHEN
12734        assert!(sql.contains("CASE WHEN"), "Expected CASE WHEN in: {}", sql);
12735    }
12736}