Sign in

    sqlparser

    Extensible SQL Lexer and Parser in MoonBit

    sql
    parser
    lexer
    Download zip
    Author
    Version
    0.5.0
    License
    Apache-2.0
    Last updated
    10 months ago
    Downloads
    44

    Dependencies

    #Extensible SQL Lexer and Parser for MoonBit

    A comprehensive SQL parser library for MoonBit that supports multiple SQL dialects and all major SQL language categories.

    #Example Usage

    // Parse a simple SELECT statement let sql = "SELECT name, age FROM users WHERE age > 18" let statements = parse_sql(sql) let pretty_output = statements.stmts[0] |> pretty_print println(pretty_output) // Parse complex queries with CTEs let complex_sql = """ WITH sales AS ( SELECT user_id, SUM(amount) as total FROM orders WHERE date > '2023-01-01' GROUP BY user_id ) SELECT u.name, s.total FROM users u JOIN sales s ON u.id = s.user_id ORDER BY s.total DESC LIMIT 10 """ let result = parse_sql(complex_sql) // Parse transaction control statements let tcl_sql = "BEGIN TRANSACTION; INSERT INTO users VALUES ('Alice'); COMMIT;" let tcl_statements = parse_sql(tcl_sql) // Parse data control statements let dcl_sql = "GRANT SELECT, INSERT ON users TO alice WITH GRANT OPTION" let dcl_result = parse_sql(dcl_sql) // Dialect-specific parsing let mysql_sql = "SHOW TABLES LIKE 'user%'" let mysql_result = parse_sql(dialect=MySQL::{}, mysql_sql)

    #Architecture

    The parser follows a modular design:

    • Lexer (lexer.mbt): Tokenizes SQL input with dialect-aware keyword recognition
    • Parser (parser.mbt): Main parsing logic with statement dispatching
    • AST (ast.mbt): Complete Abstract Syntax Tree definitions with pretty printing
    • Dialect Modules: Separate modules for each SQL dialect (mysql.mbt, postgres.mbt, etc.)
    • Language Modules:
      • dml.mbt: Data Manipulation Language parsing
      • ddl.mbt: Data Definition Language parsing
      • tcl.mbt: Transaction Control Language parsing
      • dcl.mbt: Data Control Language parsing

    #Testing

    The library includes comprehensive test coverage with 284+ tests covering:

    • All SQL statement types across all language categories
    • Dialect-specific features and syntax variations
    • Complex expressions and nested queries
    • Edge cases and error handling
    • Pretty printing accuracy

    Run tests with:
    moon test

    #Contributing

    The parser is designed for extensibility. To add new SQL features:

    1. Add keywords to keyword.mbt and lexer.mbt
    2. Define AST structures in ast.mbt
    3. Implement parsing logic in appropriate language module
    4. Add statement cases to parser.mbt

    #Contributing

    The parser is designed for extensibility. To add new SQL features:

    1. Add keywords to keyword.mbt and lexer.mbt
    2. Define AST structures in ast.mbt
    3. Implement parsing logic in appropriate language module
    4. Add statement cases to parser.mbt
    5. Write comprehensive tests

    See ROADMAP.md for planned features and implementation priorities.

    #License

    This project is licensed under the Apache 2.0 License.

    Dialect

    pub trait Dialect {
    supports_string_literal_backslash_escape(Self) -> Bool
    supports_boolean_literals(Self) -> Bool
    supports_filter_during_aggregation(Self) -> Bool
    supports_within_after_array_aggregation(Self) -> Bool
    requires_column_types_in_create_table(Self) -> Bool
    supports_if_not_exists(Self) -> Bool
    supports_double_quoted_identifiers(Self) -> Bool
    supports_array_syntax(Self) -> Bool
    supports_named_parameters(Self) -> Bool
    parse_expr(Self, tokens : ArrayView[Token]) -> (Expr, ArrayView[Token])? raise ParserError
    parse_statement(Self, parser : Parser, tokens : ArrayView[Token]) -> (Statement, ArrayView[Token])? raise ParserError
    read_keyword(Self, word : String) -> Keyword?
    }

    LexerError

    type LexerError

    impl Show for LexerError

    ParserError

    type ParserError

    impl Show for ParserError

    SqlParserError

    pub suberror SqlParserError {
    LexerError(LexerError)
    ParserError(ParserError)
    }

    ANSI

    pub(all) struct ANSI {
    }

    ANSI SQL dialect - adheres to ANSI SQL standards
    impl Dialect for ANSI

    AccessExpr

    pub(all) enum AccessExpr {
    Dot(Expr)
    Subscript(Subscript)
    }

    Access expression for array indexing, slicing, and field access
    impl Eq for AccessExpr
    impl Show for AccessExpr

    AlterIndexOperation

    pub(all) enum AlterIndexOperation {
    RenameTo(String)
    SetTablespace(String)
    Reset(Array[String])
    Set(Array[IndexParameter])
    }

    ALTER INDEX operations

    AlterIndexStmt

    pub(all) struct AlterIndexStmt {
    name : String
    if_exists : Bool
    operation : AlterIndexOperation
    }

    ALTER INDEX statement

    AlterTableOperation

    pub(all) enum AlterTableOperation {
    DropColumn(String, Bool)
    }

    AlterTableStmt

    pub(all) struct AlterTableStmt {
    table_name : ObjectName
    if_exists : Bool
    operation : AlterTableOperation
    }

    ArrayExpr

    pub(all) struct ArrayExpr {
    elem : Array[Expr]
    named : Bool
    }

    PostgreSQL array expression
    impl Eq for ArrayExpr
    impl Show for ArrayExpr

    Assignment

    pub(all) struct Assignment {
    column : String
    value : Expr
    }

    impl Eq for Assignment
    impl Show for Assignment

    BeginStmt

    pub(all) struct BeginStmt {
    work : Bool
    transaction : Bool
    }

    impl Eq for BeginStmt
    impl Show for BeginStmt

    BigQuery

    pub(all) struct BigQuery {
    }

    BigQuery dialect - supports Google BigQuery specific syntax
    impl Dialect for BigQuery

    BinaryOperator

    pub(all) enum BinaryOperator {
    Eq
    Neq
    Lt
    Gt
    LtEq
    GtEq
    Spaceship
    Plus
    Minus
    Mul
    Div
    IntegerDiv
    Mod
    And
    Or
    JsonExtract
    JsonExtractText
    JsonExtractPath
    JsonExtractPathText
    JsonContains
    JsonContainedIn
    }

    BinaryOperator::get_precedence

    fn BinaryOperator::get_precedence(self : BinaryOperator) -> Precedence

    CaseExpr

    pub(all) struct CaseExpr {
    operand : Expr?
    when_then_clauses : Array[(Expr, Expr)]
    else_expr : Expr?
    }

    CASE [operand] WHEN THEN [...] [ELSE ] END
    impl Eq for CaseExpr
    impl Show for CaseExpr

    ClickHouse

    pub(all) struct ClickHouse {
    }

    ClickHouse dialect - supports ClickHouse specific syntax

    ColumnDef

    pub(all) struct ColumnDef {
    name : String
    data_type : DataType
    options : Array[ColumnDefOption]
    }

    impl Eq for ColumnDef
    impl Show for ColumnDef

    ColumnDefOption

    pub(all) enum ColumnDefOption {
    NotNull
    Unique
    Default(Expr)
    PrimaryKey
    }

    CommitStmt

    pub(all) struct CommitStmt {
    work : Bool
    transaction : Bool
    }

    impl Eq for CommitStmt
    impl Show for CommitStmt

    ConflictAction

    pub(all) enum ConflictAction {
    DoNothing
    DoUpdate(Array[Assignment], Expr?)
    }

    Action to take when conflict occurs

    ConflictTarget

    pub(all) enum ConflictTarget {
    Columns(Array[String])
    OnConstraint(String)
    OnExpression(Expr, Expr?)
    }

    Conflict target specification

    CopyDirection

    pub(all) enum CopyDirection {
    To
    From
    }

    Direction of COPY operation
    impl Eq for CopyDirection

    CopyForceQuote

    pub(all) enum CopyForceQuote {
    All
    Columns(Array[String])
    }

    FORCE_QUOTE specification

    CopyFormat

    pub(all) enum CopyFormat {
    Csv
    Text
    Binary
    }

    COPY format specification
    impl Eq for CopyFormat
    impl Show for CopyFormat

    CopyOption

    pub(all) enum CopyOption {
    Format(CopyFormat)
    Delimiter(String)
    Null(String)
    Header(Bool?)
    Quote(String)
    Escape(String)
    ForceQuote(CopyForceQuote)
    ForceNotNull(Array[String])
    ForceNull(Array[String])
    Encoding(String)
    }

    COPY statement options
    impl Eq for CopyOption
    impl Show for CopyOption

    CopySource

    pub(all) enum CopySource {
    Table(ObjectName, Array[String]?)
    Query(QueryStmt)
    }

    Source specification for COPY statement
    impl Eq for CopySource
    impl Show for CopySource

    CopyStmt

    pub(all) struct CopyStmt {
    source : CopySource
    direction : CopyDirection
    target : CopyTarget
    format_options : Array[CopyOption]
    }

    COPY statement for bulk data import/export operations
    impl Eq for CopyStmt
    impl Show for CopyStmt

    CopyTarget

    pub(all) enum CopyTarget {
    File(String)
    Stdin
    Stdout
    Program(String)
    }

    Target specification for COPY statement
    impl Eq for CopyTarget
    impl Show for CopyTarget

    CreateDatabaseStmt

    pub(all) struct CreateDatabaseStmt {
    name : String
    if_not_exists : Bool
    character_set : String?
    collate : String?
    }

    CREATE DATABASE statement

    CreateFunctionStmt

    pub(all) struct CreateFunctionStmt {
    name : String
    parameters : Array[FunctionParameter]
    return_type : DataType?
    language : String?
    body : String?
    deterministic : Bool
    if_not_exists : Bool
    }

    CREATE FUNCTION statement

    CreateIndexStmt

    pub(all) struct CreateIndexStmt {
    unique : Bool
    concurrently : Bool
    if_not_exists : Bool
    name : String
    table_name : ObjectName
    index_method : IndexMethod?
    columns : Array[IndexColumn]
    where_clause : Expr?
    }

    CREATE INDEX statement

    CreateProcedureStmt

    pub(all) struct CreateProcedureStmt {
    name : String
    parameters : Array[FunctionParameter]
    language : String?
    body : String?
    if_not_exists : Bool
    }

    CREATE PROCEDURE statement

    CreateSchemaStmt

    pub(all) struct CreateSchemaStmt {
    name : String
    if_not_exists : Bool
    authorization : String?
    }

    CREATE SCHEMA statement (synonym for CREATE DATABASE in many dialects)

    CreateSequenceStmt

    pub(all) struct CreateSequenceStmt {
    name : String
    if_not_exists : Bool
    temporary : Bool
    increment : Int?
    minvalue : SequenceLimit?
    maxvalue : SequenceLimit?
    start_with : Int?
    cache : Int?
    cycle : Bool?
    owned_by : SequenceOwnedBy?
    }

    CREATE SEQUENCE statement

    CreateTableDefinition

    pub(all) enum CreateTableDefinition {
    Columns(Array[ColumnDef], Array[TableConstraint])
    AsQuery(QueryStmt)
    }

    CreateTableStmt

    pub(all) struct CreateTableStmt {
    name : String
    if_not_exists : Bool
    definition : CreateTableDefinition
    }

    CreateViewStmt

    type CreateViewStmt

    Cte

    pub(all) struct Cte {
    name : String
    query : QueryStmt
    columns : Array[String]?
    }

    Common Table Expression (CTE) for WITH clauses
    impl Eq for Cte
    impl Show for Cte

    DataType

    pub(all) enum DataType {
    Integer
    Smallint
    Bigint
    Float(Int?)
    Real
    Double
    Char(Int)
    Varchar(Int)
    Text
    Boolean
    Timestamp
    Blob
    }

    impl Eq for DataType
    impl Show for DataType

    DatetimeUnit

    pub(all) enum DatetimeUnit {
    Year
    Month
    Day
    Hour
    Minute
    Second
    }

    impl Eq for DatetimeUnit

    DeallocateStmt

    pub(all) struct DeallocateStmt {
    name : String
    prepare : Bool
    }

    DEALLOCATE statement Syntax: DEALLOCATE [PREPARE] name

    DeleteStmt

    pub(all) struct DeleteStmt {
    table_name : ObjectName
    where_clause : Expr?
    }

    impl Eq for DeleteStmt
    impl Show for DeleteStmt

    DropIndexStmt

    pub(all) struct DropIndexStmt {
    name : String
    if_exists : Bool
    concurrently : Bool
    table_name : ObjectName?
    }

    impl Eq for DropIndexStmt

    DropTableStmt

    pub(all) struct DropTableStmt {
    table_name : ObjectName
    if_exists : Bool
    }

    impl Eq for DropTableStmt

    DropViewStmt

    pub(all) struct DropViewStmt {
    name : String
    }

    impl Eq for DropViewStmt

    DuckDB

    pub(all) struct DuckDB {
    }

    DuckDB dialect - supports DuckDB specific syntax
    impl Dialect for DuckDB

    DuplicateTreatment

    pub(all) enum DuplicateTreatment {
    Distinct
    All
    }

    ExecuteStmt

    pub(all) struct ExecuteStmt {
    name : ObjectName?
    parameters : Array[Expr]
    has_parentheses : Bool
    into : Array[String]
    using_exprs : Array[Expr]
    }

    EXECUTE statement Syntax: EXECUTE name [(param [, ...])] EXECUTE name USING expr [, ...] EXECUTE IMMEDIATE 'sql_string' [INTO var [, ...]] [USING expr [, ...]]
    impl Eq for ExecuteStmt
    impl Show for ExecuteStmt

    Expr

    pub(all) enum Expr {
    Identifier(String)
    CompoundIdentifier(Array[String])
    Literal(Literal)
    BinaryOperation(Expr, BinaryOperator, Expr)
    UnaryOperation(UnaryOperator, Expr)
    FunctionCall(String, DuplicateTreatment?, Array[Expr], Expr?)
    Wildcard
    Datetime(String)
    Interval(String, IntervalQualifier)
    Like(Bool, Expr, Expr)
    ILike(Bool, Expr, Expr)
    SubQuery(QueryStmt)
    Exists(Bool, QueryStmt)
    Between(Bool, Expr, Expr, Expr)
    Extract(PrimaryDatetimeField, Expr)
    Case(CaseExpr)
    InList(Bool, Expr, Array[Expr])
    InSubQuery(Bool, Expr, QueryStmt)
    Substring(Expr, Expr?, Expr?)
    Placeholder(String)
    Array(ArrayExpr)
    CompoundFieldAccess(Expr, Array[AccessExpr])
    WindowFunction(String, DuplicateTreatment?, Array[Expr], WindowSpec)
    }

    impl Eq for Expr
    impl Show for Expr

    FunctionParameter

    pub(all) struct FunctionParameter {
    name : String
    param_type : DataType
    mode : ParameterMode?
    }

    Function parameter definition

    Generic

    pub(all) struct Generic {
    }

    Generic SQL dialect that supports the union of all other dialects This is the most permissive dialect, useful for parsing various SQL statements from different sources without strict dialect requirements
    impl Dialect for Generic

    GrantStmt

    pub(all) struct GrantStmt {
    privileges : Array[Privilege]
    objects : Array[ObjectName]
    grantees : Array[String]
    with_grant_option : Bool
    }

    impl Eq for GrantStmt
    impl Show for GrantStmt

    IndexColumn

    pub(all) struct IndexColumn {
    name : Expr
    asc : Bool?
    nulls_first : Bool?
    }

    Index column specification
    impl Eq for IndexColumn
    impl Show for IndexColumn

    IndexMethod

    pub(all) enum IndexMethod {
    Btree
    Hash
    Gin
    Gist
    Spgist
    Brin
    }

    Index creation method
    impl Eq for IndexMethod
    impl Show for IndexMethod

    IndexParameter

    pub(all) struct IndexParameter {
    name : String
    value : String
    }

    Index parameter for SET operations

    InsertSource

    pub(all) enum InsertSource {
    Values(Array[Array[Expr]])
    Query(QueryStmt)
    }

    impl Eq for InsertSource

    InsertStmt

    pub(all) struct InsertStmt {
    table_name : ObjectName
    columns : Array[String]
    source : InsertSource
    or : SqliteOnConflict?
    on : OnInsert?
    }

    impl Eq for InsertStmt
    impl Show for InsertStmt

    IntervalQualifier

    pub(all) enum IntervalQualifier {
    Single(PrimaryDatetimeField)
    Range(PrimaryDatetimeField, PrimaryDatetimeField)
    }

    Join

    pub(all) struct Join {
    table_ref : TableRef
    join_operator : JoinOperator
    }

    impl Eq for Join
    impl Show for Join

    JoinConstraint

    pub(all) enum JoinConstraint {
    On(Expr)
    Using(Array[String])
    Non
    }

    JoinOperator

    pub(all) enum JoinOperator {
    Join(JoinConstraint)
    Left(JoinConstraint)
    LeftOuter(JoinConstraint)
    Right(JoinConstraint)
    RightOuter(JoinConstraint)
    Full(JoinConstraint)
    FullOuter(JoinConstraint)
    Inner(JoinConstraint)
    Cross
    }

    impl Eq for JoinOperator

    Keyword

    pub(all) enum Keyword {
    Select
    From
    Where
    As
    Group
    Order
    By
    Asc
    Desc
    Nulls
    First
    Last
    Year
    Month
    Day
    Hour
    Minute
    Second
    Date
    Interval
    To
    Like
    Not
    ILike
    Exists
    Between
    And
    Or
    Extract
    Filter
    Case
    When
    Matched
    Target
    Then
    Else
    Having
    End
    In
    Join
    Left
    Right
    Full
    Outer
    Inner
    Cross
    On
    Using
    Limit
    Offset
    Create
    Table
    Integer
    Int
    Smallint
    Bigint
    Real
    Double
    Precision
    Char
    Character
    Collate
    Authorization
    Varchar
    Varing
    Text
    Time
    Boolean
    Float
    Timestamp
    Blob
    Null
    Default
    Unique
    View
    Drop
    Distinct
    All
    Substring
    For
    Primary
    Key
    Foreign
    References
    Check
    Union
    Intersect
    Except
    Top
    Insert
    Into
    Values
    Merge
    If
    Delete
    Update
    Set
    Replace
    Rollback
    Abort
    Fail
    Ignore
    Truncate
    Alter
    Column
    Show
    Tables
    Columns
    Status
    Databases
    Database
    Div
    Lock
    Unlock
    Listen
    Notify
    Schemas
    Schema
    Variables
    Processlist
    Grants
    Functions
    Function
    Extended
    Global
    Session
    Procedure
    Returns
    Language
    Deterministic
    Event
    Trigger
    Duplicate
    Conflict
    Do
    Nothing
    Constraint
    Array
    With
    Begin
    Start
    Transaction
    Commit
    Savepoint
    Release
    Work
    Grant
    Revoke
    Privileges
    Usage
    Use
    Execute
    Prepare
    Deallocate
    Immediate
    Connect
    Temporary
    Temp
    Option
    Restrict
    Cascade
    Index
    Copy
    Format
    Stdin
    Stdout
    Program
    Header
    ForceQuote
    ForceNotNull
    ForceNull
    Encoding
    Load
    Data
    Local
    Infile
    Fields
    Lines
    Terminated
    Enclosed
    Escaped
    Starting
    Optionally
    Rename
    Tablespace
    Reset
    Btree
    Hash
    Gin
    Gist
    Spgist
    Brin
    Concurrently
    Over
    Window
    Partition
    Rows
    Range
    Preceding
    Following
    Current
    Unbounded
    Row
    Out
    InOut
    Sequence
    Increment
    Minvalue
    Maxvalue
    Cache
    Cycle
    Owned
    No
    }

    impl Eq for Keyword
    impl Show for Keyword

    Literal

    pub(all) enum Literal {
    Integer(Int)
    Double(Double)
    String(String)
    Boolean(Bool)
    Null
    }

    impl Eq for Literal
    impl Show for Literal

    LoadDataDuplicateHandling

    pub(all) enum LoadDataDuplicateHandling {
    Replace
    Ignore
    }

    Duplicate handling for LOAD DATA

    LoadDataFieldsOptions

    pub(all) struct LoadDataFieldsOptions {
    terminated_by : String?
    enclosed_by : String?
    optionally_enclosed : Bool
    escaped_by : String?
    }

    FIELDS options for LOAD DATA

    LoadDataLinesOptions

    pub(all) struct LoadDataLinesOptions {
    starting_by : String?
    terminated_by : String?
    }

    LINES options for LOAD DATA

    LoadDataStmt

    pub(all) struct LoadDataStmt {
    is_local : Bool
    filename : String
    duplicate_handling : LoadDataDuplicateHandling?
    table_name : ObjectName
    character_set : String?
    fields_options : LoadDataFieldsOptions?
    lines_options : LoadDataLinesOptions?
    ignore_lines : Int?
    columns : Array[String]?
    set_assignments : Array[Assignment]?
    }

    LOAD DATA statement for MySQL-style bulk data loading
    impl Eq for LoadDataStmt

    MergeAction

    pub(all) enum MergeAction {
    Insert(Array[String], Array[Expr])
    Update(Array[Assignment])
    Delete
    }

    Actions that can be performed in MERGE
    impl Eq for MergeAction
    impl Show for MergeAction

    MergeMatchType

    pub(all) enum MergeMatchType {
    Matched
    NotMatched
    }

    Match type for WHEN clause

    MergeSource

    pub(all) enum MergeSource {
    Table(ObjectName)
    Query(QueryStmt)
    }

    Source for MERGE statement
    impl Eq for MergeSource
    impl Show for MergeSource

    MergeStmt

    pub(all) struct MergeStmt {
    target_table : ObjectName
    target_alias : String?
    source : MergeSource
    source_alias : String?
    join_condition : Expr
    when_clauses : Array[MergeWhenClause]
    }

    MERGE statement for conditional INSERT/UPDATE/DELETE operations
    impl Eq for MergeStmt
    impl Show for MergeStmt

    MergeWhenClause

    pub(all) struct MergeWhenClause {
    match_type : MergeMatchType
    condition : Expr?
    action : MergeAction
    }

    WHEN clause in MERGE statement

    MySQL

    pub(all) struct MySQL {
    }

    impl Dialect for MySQL

    ObjectName

    pub(all) struct ObjectName {
    parts : Array[String]
    }

    impl Eq for ObjectName
    impl Show for ObjectName

    OnConflictClause

    pub(all) struct OnConflictClause {
    conflict_target : ConflictTarget?
    conflict_action : ConflictAction
    }

    PostgreSQL ON CONFLICT clause for advanced conflict resolution Syntax: ON CONFLICT [ conflict_target ] conflict_action

    OnInsert

    pub(all) enum OnInsert {
    DuplicateKeyUpdate(Array[Assignment])
    OnConflict(OnConflictClause)
    }

    MySQL ON DUPLICATE KEY UPDATE or PostgreSQL ON CONFLICT
    impl Eq for OnInsert
    impl Show for OnInsert

    OrderByExpr

    pub(all) struct OrderByExpr {
    expr : Expr
    asc : Bool?
    nulls_first : Bool?
    }

    impl Eq for OrderByExpr
    impl Show for OrderByExpr

    ParameterMode

    pub(all) enum ParameterMode {
    In
    Out
    InOut
    }

    Parameter mode for functions/procedures
    impl Eq for ParameterMode

    Parser

    pub struct Parser {
    dialect : &Dialect
    }

    Postgres

    pub(all) struct Postgres {
    }

    impl Dialect for Postgres

    Precedence

    pub(all) enum Precedence {
    PlusMinus
    MulDivMod
    Eq
    Like
    And
    Or
    Between
    UnaryNot
    JsonOperator
    }

    Precedence::value

    fn Precedence::value(self : Precedence) -> Int

    PrepareStmt

    pub(all) struct PrepareStmt {
    name : String
    data_types : Array[DataType]
    statement : Statement
    }

    PREPARE statement Syntax: PREPARE name [(data_type [, ...])] AS statement
    impl Eq for PrepareStmt
    impl Show for PrepareStmt

    PrimaryDatetimeField

    type PrimaryDatetimeField

    Privilege

    pub(all) enum Privilege {
    Select(Array[String]?)
    Insert(Array[String]?)
    Update(Array[String]?)
    Delete
    References(Array[String]?)
    Create
    Drop
    Alter
    Index
    All
    Usage
    Execute
    Connect
    Temporary
    }

    impl Eq for Privilege
    impl Show for Privilege

    Projection

    pub(all) enum Projection {
    Wildcard
    UnamedExpr(Expr)
    AliasedExpr(Expr, String)
    }

    impl Eq for Projection
    impl Show for Projection

    QueryStmt

    pub(all) struct QueryStmt {
    with_clause : Array[Cte]?
    body : SetExpr
    order_by : Array[OrderByExpr]
    limit : Expr?
    offset : Expr?
    }

    impl Eq for QueryStmt
    impl Show for QueryStmt

    Redshift

    pub(all) struct Redshift {
    }

    Redshift dialect - supports Amazon Redshift specific syntax
    impl Dialect for Redshift

    ReleaseSavepointStmt

    pub(all) struct ReleaseSavepointStmt {
    savepoint_keyword : Bool
    name : String
    }

    RevokeOption

    pub(all) enum RevokeOption {
    Restrict
    Cascade
    }

    impl Eq for RevokeOption

    RevokeStmt

    pub(all) struct RevokeStmt {
    grant_option_for : Bool
    privileges : Array[Privilege]
    objects : Array[ObjectName]
    grantees : Array[String]
    cascade : RevokeOption?
    }

    impl Eq for RevokeStmt
    impl Show for RevokeStmt

    RollbackStmt

    pub(all) struct RollbackStmt {
    work : Bool
    transaction : Bool
    savepoint : String?
    }

    impl Eq for RollbackStmt

    SQLite

    pub(all) struct SQLite {
    }

    impl Dialect for SQLite

    SavepointStmt

    pub(all) struct SavepointStmt {
    name : String
    }

    impl Eq for SavepointStmt

    SelectStmt

    type SelectStmt

    impl Eq for SelectStmt
    impl Show for SelectStmt

    SequenceLimit

    pub(all) enum SequenceLimit {
    Value(Int)
    NoLimit
    }

    Sequence limit specification
    impl Eq for SequenceLimit

    SequenceOwnedBy

    pub(all) enum SequenceOwnedBy {
    Column(ObjectName, String)
    ByNone
    }

    OWNED BY specification for sequences

    SetAssignment

    pub(all) struct SetAssignment {
    variable : String
    value : Expr
    }

    impl Eq for SetAssignment

    SetExpr

    type SetExpr

    impl Eq for SetExpr
    impl Show for SetExpr

    SetOperator

    type SetOperator

    impl Eq for SetOperator
    impl Show for SetOperator

    SetScope

    pub(all) enum SetScope {
    Global
    Session
    UserVar
    Local
    }

    impl Eq for SetScope
    impl Show for SetScope

    SetStmt

    pub(all) struct SetStmt {
    scope : SetScope
    assignments : Array[SetAssignment]
    }

    impl Eq for SetStmt
    impl Show for SetStmt

    ShowFilter

    pub(all) enum ShowFilter {
    Like(String)
    Where(Expr)
    }

    impl Eq for ShowFilter
    impl Show for ShowFilter

    ShowStmt

    pub(all) struct ShowStmt {
    show_type : ShowType
    object : ObjectName?
    filter : ShowFilter?
    extended : Bool
    full : Bool
    global_scope : Bool
    }

    MySQL SHOW statement
    impl Eq for ShowStmt
    impl Show for ShowStmt

    ShowType

    pub(all) enum ShowType {
    Tables
    Columns
    Status
    Databases
    Schemas
    Variables
    Processlist
    Grants
    Functions
    CreateTable
    CreateView
    CreateFunction
    CreateProcedure
    CreateEvent
    CreateTrigger
    }

    impl Eq for ShowType
    impl Show for ShowType

    Snowflake

    pub(all) struct Snowflake {
    }

    Snowflake dialect - supports Snowflake specific syntax

    SqliteOnConflict

    pub(all) enum SqliteOnConflict {
    Rollback
    Abort
    Fail
    Ignore
    Replace
    }

    SQLite-style conflict resolution for INSERT statements See: https://sqlite.org/lang_conflict.html

    Statement

    pub(all) enum Statement {
    Query(QueryStmt)
    CreateTable(CreateTableStmt)
    CreateView(CreateViewStmt)
    CreateIndex(CreateIndexStmt)
    CreateDatabase(CreateDatabaseStmt)
    CreateSchema(CreateSchemaStmt)
    CreateFunction(CreateFunctionStmt)
    CreateProcedure(CreateProcedureStmt)
    CreateSequence(CreateSequenceStmt)
    DropView(DropViewStmt)
    DropTable(DropTableStmt)
    DropIndex(DropIndexStmt)
    Insert(InsertStmt)
    Delete(DeleteStmt)
    Update(UpdateStmt)
    Merge(MergeStmt)
    Truncate(TruncateStmt)
    AlterTable(AlterTableStmt)
    AlterIndex(AlterIndexStmt)
    Show(ShowStmt)
    Set(SetStmt)
    Use(UseStmt)
    Copy(CopyStmt)
    LoadData(LoadDataStmt)
    Prepare(PrepareStmt)
    Execute(ExecuteStmt)
    Deallocate(DeallocateStmt)
    LockTables(Array[ObjectName])
    UnlockTables
    Listen(String)
    Notify(String, String?)
    Begin(BeginStmt)
    Commit(CommitStmt)
    Rollback(RollbackStmt)
    Savepoint(SavepointStmt)
    ReleaseSavepoint(ReleaseSavepointStmt)
    Grant(GrantStmt)
    Revoke(RevokeStmt)
    }

    impl Eq for Statement
    impl Show for Statement

    Statements

    pub(all) struct Statements {
    stmts : Array[Statement]
    }

    impl Eq for Statements
    impl Show for Statements

    Statements::op_get

    fn Statements::op_get(self : Statements, index : Int) -> Statement

    Subscript

    pub(all) enum Subscript {
    Index(Expr)
    Slice(Expr?, Expr?, Expr?)
    }

    Subscript expression for array indexing and slicing
    impl Eq for Subscript
    impl Show for Subscript

    TableAlias

    pub(all) struct TableAlias {
    name : String
    columns : Array[String]
    }

    impl Eq for TableAlias
    impl Show for TableAlias

    TableConstraint

    pub(all) enum TableConstraint {
    Unique(Array[OrderByExpr])
    PrimaryKey(Array[OrderByExpr])
    ForeignKey(Array[OrderByExpr], ObjectName, Array[String])
    Check(Expr)
    }

    TableFactor

    pub(all) enum TableFactor {
    Column(ObjectName, TableAlias?)
    SubQuery(QueryStmt, TableAlias?)
    }

    impl Eq for TableFactor
    impl Show for TableFactor

    TableRef

    pub(all) struct TableRef {
    factor : TableFactor
    joins : Array[Join]
    }

    impl Eq for TableRef
    impl Show for TableRef

    Token

    pub(all) enum Token {
    Keyword(Keyword)
    Identifier(String)
    Number(String)
    StringLiteral(String)
    Boolean(Bool)
    Comma
    Semicolon
    Colon
    Eq
    DoubleEq
    Neq
    Lt
    Gt
    LtEq
    GtEq
    Spaceship
    Plus
    Minus
    Mul
    Div
    Mod
    LBracket
    RBracket
    LBrace
    RBrace
    LParen
    RParen
    Period
    Placeholder(String)
    JsonExtract
    JsonExtractText
    JsonExtractPath
    JsonExtractPathText
    JsonContains
    JsonContainedIn
    Unknown(Char)
    Eof
    }

    impl Eq for Token
    impl Show for Token

    Top

    pub(all) enum Top {
    Constant(Int)
    Expr(Expr)
    }

    impl Eq for Top
    impl Show for Top

    TruncateStmt

    pub(all) struct TruncateStmt {
    table_name : ObjectName
    }

    impl Eq for TruncateStmt

    UnaryOperator

    pub(all) enum UnaryOperator {
    Plus
    Minus
    Not
    }

    impl Eq for UnaryOperator

    UpdateStmt

    pub(all) struct UpdateStmt {
    table_name : ObjectName
    assignments : Array[Assignment]
    where_clause : Expr?
    }

    impl Eq for UpdateStmt
    impl Show for UpdateStmt

    UseStmt

    pub(all) struct UseStmt {
    database_name : ObjectName
    }

    USE database statement for database switching
    impl Eq for UseStmt
    impl Show for UseStmt

    ViewColumnDef

    pub(all) struct ViewColumnDef {
    name : String
    }

    impl Eq for ViewColumnDef

    WindowFrameBound

    pub(all) enum WindowFrameBound {
    UnboundedPreceding
    UnboundedFollowing
    CurrentRow
    Preceding(Expr)
    Following(Expr)
    }

    Window frame bound

    WindowFrameClause

    pub(all) struct WindowFrameClause {
    frame_units : WindowFrameUnits
    frame_start : WindowFrameBound
    frame_end : WindowFrameBound?
    }

    Window frame clause

    WindowFrameUnits

    pub(all) enum WindowFrameUnits {
    Rows
    Range
    }

    Window frame units

    WindowSpec

    pub(all) struct WindowSpec {
    partition_by : Array[Expr]
    order_by : Array[OrderByExpr]
    frame_clause : WindowFrameClause?
    }

    Window function specification: OVER ([PARTITION BY ...] [ORDER BY ...] [frame_clause])
    impl Eq for WindowSpec
    impl Show for WindowSpec

    parse

    fn parse(tokens : ArrayView[Token], dialect? : &Dialect) -> Array[Statement] raise ParserError

    parse_sql

    fn parse_sql(dialect? : &Dialect, input : String) -> Statements raise SqlParserError

    pretty_print

    fn[T :
    Pretty
    ] pretty_print(obj : T) -> String

    structural_print

    fn[T : Show] structural_print(obj : T) -> String

    tokenize

    fn tokenize(dialect? : &Dialect, input : String) -> Array[Token] raise LexerError