use itertools::Itertools;
use sqruff_lib_core::dialects::Dialect;
use sqruff_lib_core::dialects::init::DialectKind;
use sqruff_lib_core::dialects::syntax::SyntaxKind;
use sqruff_lib_core::helpers::{Config, ToMatchable};
use sqruff_lib_core::parser::grammar::anyof::{
    AnyNumberOf, any_set_of, one_of, optionally_bracketed,
};
use sqruff_lib_core::parser::grammar::delimited::Delimited;
use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence};
use sqruff_lib_core::parser::grammar::{Anything, Ref};
use sqruff_lib_core::parser::lexer::Matcher;
use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait};
use sqruff_lib_core::parser::node_matcher::NodeMatcher;
use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser};
use sqruff_lib_core::parser::segments::generator::SegmentGenerator;
use sqruff_lib_core::parser::segments::meta::MetaSegment;
use sqruff_lib_core::parser::types::ParseMode;

use super::ansi;
use super::postgres_keywords::POSTGRES_POSTGIS_DATATYPE_KEYWORDS;
use crate::postgres_keywords::{get_keywords, postgres_keywords};
use sqruff_lib_core::dialects::init::DialectConfig;
use sqruff_lib_core::value::Value;

sqruff_lib_core::dialect_config!(PostgresDialectConfig {
    /// Enable parsing of pg_trgm trigram operators
    pg_trgm: "Enable parsing of pg_trgm trigram operators (%, <%, %>, <->, etc.)",
    /// Enable parsing of pgvector data types
    pgvector: "Enable parsing of pgvector data types (VECTOR, HALFVEC, SPARSEVEC)."
});

pub fn dialect(config: Option<&Value>) -> Dialect {
    // Parse and validate dialect configuration, falling back to defaults on failure
    let dialect_config: PostgresDialectConfig = config
        .map(PostgresDialectConfig::from_value)
        .unwrap_or_default();

    let mut postgres = raw_dialect();

    if dialect_config.pg_trgm {
        postgres.insert_lexer_matchers(
            vec![Matcher::regex(
                "trgm_operator",
                r#"(<<<->|<->>>|<<->|<->>|<->|<<%|%>>|%>|<%|%)"#,
                SyntaxKind::LikeOperator,
            )],
            "like_operator",
        );
    }

    if dialect_config.pgvector {
        postgres.replace_grammar("DatatypeSegment", build_datatype_segment_grammar(true));

        // Add pgvector distance operators: <-> (L2), <=> (cosine), <+> (L1), <#> (inner product)
        postgres.insert_lexer_matchers(
            vec![Matcher::regex(
                "pgvector_operator",
                r#"(<->|<=>|<\+>|<#>)"#,
                SyntaxKind::PgvectorOperator,
            )],
            "greater_than",
        );

        // Register PgvectorOperatorSegment as a comparison operator
        postgres.add([(
            "PgvectorOperatorSegment".into(),
            TypedParser::new(SyntaxKind::PgvectorOperator, SyntaxKind::ComparisonOperator)
                .to_matchable()
                .into(),
        )]);

        // Extend ComparisonOperatorGrammar to include pgvector operators
        postgres.replace_grammar(
            "ComparisonOperatorGrammar",
            build_comparison_operator_grammar(true),
        );
    }

    postgres.config(|dialect| dialect.expand())
}

/// Build the ComparisonOperatorGrammar, optionally including pgvector operators.
fn build_comparison_operator_grammar(pgvector: bool) -> Matchable {
    let mut operators = vec![
        Ref::new("EqualsSegment").to_matchable(),
        Ref::new("GreaterThanSegment").to_matchable(),
        Ref::new("LessThanSegment").to_matchable(),
        Ref::new("GreaterThanOrEqualToSegment").to_matchable(),
        Ref::new("LessThanOrEqualToSegment").to_matchable(),
        Ref::new("NotEqualToSegment").to_matchable(),
        Ref::new("LikeOperatorSegment").to_matchable(),
        Sequence::new(vec![
            Ref::keyword("IS").to_matchable(),
            Ref::keyword("DISTINCT").to_matchable(),
            Ref::keyword("FROM").to_matchable(),
        ])
        .to_matchable(),
        Sequence::new(vec![
            Ref::keyword("IS").to_matchable(),
            Ref::keyword("NOT").to_matchable(),
            Ref::keyword("DISTINCT").to_matchable(),
            Ref::keyword("FROM").to_matchable(),
        ])
        .to_matchable(),
        Ref::new("OverlapSegment").to_matchable(),
        Ref::new("NotExtendRightSegment").to_matchable(),
        Ref::new("NotExtendLeftSegment").to_matchable(),
        Ref::new("AdjacentSegment").to_matchable(),
    ];

    if pgvector {
        operators.push(Ref::new("PgvectorOperatorSegment").to_matchable());
    }

    one_of(operators).to_matchable()
}

/// Build the DatatypeSegment grammar, optionally including pgvector types.
fn build_datatype_segment_grammar(pgvector: bool) -> Matchable {
    let mut known_types: Vec<Matchable> = vec![
        Ref::keyword("SMALLINT").to_matchable(),
        Ref::keyword("INTEGER").to_matchable(),
        Ref::keyword("INT").to_matchable(),
        Ref::keyword("INT2").to_matchable(),
        Ref::keyword("INT4").to_matchable(),
        Ref::keyword("INT8").to_matchable(),
        Ref::keyword("BIGINT").to_matchable(),
        Ref::keyword("FLOAT4").to_matchable(),
        Ref::keyword("FLOAT8").to_matchable(),
        Ref::keyword("REAL").to_matchable(),
        Sequence::new(vec![
            Ref::keyword("DOUBLE").to_matchable(),
            Ref::keyword("PRECISION").to_matchable(),
        ])
        .to_matchable(),
        Ref::keyword("SMALLSERIAL").to_matchable(),
        Ref::keyword("SERIAL").to_matchable(),
        Ref::keyword("SERIAL2").to_matchable(),
        Ref::keyword("SERIAL4").to_matchable(),
        Ref::keyword("SERIAL8").to_matchable(),
        Ref::keyword("BIGSERIAL").to_matchable(),
        // Numeric types [(precision)]
        Sequence::new(vec![
            one_of(vec![Ref::keyword("FLOAT").to_matchable()]).to_matchable(),
            Ref::new("BracketedArguments").optional().to_matchable(),
        ])
        .to_matchable(),
        // Numeric types [precision ["," scale])]
        Sequence::new(vec![
            one_of(vec![
                Ref::keyword("DECIMAL").to_matchable(),
                Ref::keyword("NUMERIC").to_matchable(),
            ])
            .to_matchable(),
            Ref::new("BracketedArguments").optional().to_matchable(),
        ])
        .to_matchable(),
        // Monetary type
        Ref::keyword("MONEY").to_matchable(),
        // Character types
        one_of(vec![
            Sequence::new(vec![
                one_of(vec![
                    Ref::keyword("BPCHAR").to_matchable(),
                    Ref::keyword("CHAR").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("CHAR").to_matchable(),
                        Ref::keyword("VARYING").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("CHARACTER").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("CHARACTER").to_matchable(),
                        Ref::keyword("VARYING").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("VARCHAR").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("BracketedArguments").optional().to_matchable(),
            ])
            .to_matchable(),
            Ref::keyword("TEXT").to_matchable(),
        ])
        .to_matchable(),
        // Binary type
        Ref::keyword("BYTEA").to_matchable(),
        // Boolean types
        one_of(vec![
            Ref::keyword("BOOLEAN").to_matchable(),
            Ref::keyword("BOOL").to_matchable(),
        ])
        .to_matchable(),
        // Geometric types
        one_of(vec![
            Ref::keyword("POINT").to_matchable(),
            Ref::keyword("LINE").to_matchable(),
            Ref::keyword("LSEG").to_matchable(),
            Ref::keyword("BOX").to_matchable(),
            Ref::keyword("PATH").to_matchable(),
            Ref::keyword("POLYGON").to_matchable(),
            Ref::keyword("CIRCLE").to_matchable(),
        ])
        .to_matchable(),
        // Network address types
        one_of(vec![
            Ref::keyword("CIDR").to_matchable(),
            Ref::keyword("INET").to_matchable(),
            Ref::keyword("MACADDR").to_matchable(),
            Ref::keyword("MACADDR8").to_matchable(),
        ])
        .to_matchable(),
        // Text search types
        one_of(vec![
            Ref::keyword("TSVECTOR").to_matchable(),
            Ref::keyword("TSQUERY").to_matchable(),
        ])
        .to_matchable(),
        // Bit string types
        Sequence::new(vec![
            Ref::keyword("BIT").to_matchable(),
            one_of(vec![Ref::keyword("VARYING").to_matchable()])
                .config(|this| this.optional())
                .to_matchable(),
            Ref::new("BracketedArguments").optional().to_matchable(),
        ])
        .to_matchable(),
        // UUID type
        Ref::keyword("UUID").to_matchable(),
        // XML type
        Ref::keyword("XML").to_matchable(),
        // JSON types
        one_of(vec![
            Ref::keyword("JSON").to_matchable(),
            Ref::keyword("JSONB").to_matchable(),
        ])
        .to_matchable(),
        // Range types
        Ref::keyword("INT4RANGE").to_matchable(),
        Ref::keyword("INT8RANGE").to_matchable(),
        Ref::keyword("NUMRANGE").to_matchable(),
        Ref::keyword("TSRANGE").to_matchable(),
        Ref::keyword("TSTZRANGE").to_matchable(),
        Ref::keyword("DATERANGE").to_matchable(),
        // pg_lsn type
        Ref::keyword("PG_LSN").to_matchable(),
    ];

    // pgvector extension types (VECTOR, HALFVEC, SPARSEVEC with optional dimensions)
    if pgvector {
        known_types.push(
            Sequence::new(vec![
                one_of(vec![
                    Ref::keyword("VECTOR").to_matchable(),
                    Ref::keyword("HALFVEC").to_matchable(),
                    Ref::keyword("SPARSEVEC").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("BracketedArguments").optional().to_matchable(),
            ])
            .to_matchable(),
        );
    }

    Sequence::new(vec![
        Sequence::new(vec![
            Ref::new("SingleIdentifierGrammar").to_matchable(),
            Ref::new("DotSegment").to_matchable(),
        ])
        .config(|this| {
            this.allow_gaps = false;
            this.optional();
        })
        .to_matchable(),
        one_of(vec![
            Ref::new("WellKnownTextGeometrySegment").to_matchable(),
            Ref::new("DateTimeTypeIdentifier").to_matchable(),
            Sequence::new(vec![one_of(known_types).to_matchable()]).to_matchable(),
            Ref::new("DatatypeIdentifierSegment").to_matchable(),
        ])
        .to_matchable(),
        one_of(vec![
            AnyNumberOf::new(vec![
                Bracketed::new(vec![
                    Ref::new("ExpressionSegment").optional().to_matchable(),
                ])
                .config(|this| this.bracket_type("square"))
                .to_matchable(),
            ])
            .to_matchable(),
            Ref::new("ArrayTypeSegment").to_matchable(),
            Ref::new("SizedArrayTypeSegment").to_matchable(),
        ])
        .config(|this| this.optional())
        .to_matchable(),
    ])
    .to_matchable()
}

pub fn raw_dialect() -> Dialect {
    let mut postgres = ansi::raw_dialect();
    postgres.name = DialectKind::Postgres;

    postgres.insert_lexer_matchers(
        vec![Matcher::string("right_arrow", "=>", SyntaxKind::RightArrow)],
        "equals",
    );

    postgres.insert_lexer_matchers(vec![
        Matcher::legacy(
            "unicode_single_quote",
            |s| s.starts_with("U&'"),
            r"(?s)U&(('')+?(?!')|('.*?(?<!')(?:'')*'(?!')))(\s*UESCAPE\s*'[^0-9A-Fa-f'+\-\s)]')?",
            SyntaxKind::UnicodeSingleQuote
        ),
        Matcher::legacy(
            "escaped_single_quote",
            |s| s.starts_with("E'"),
            r"(?s)E(('')+?(?!')|'.*?((?<!\\)(?:\\\\)*(?<!')(?:'')*|(?<!\\)(?:\\\\)*\\(?<!')(?:'')*')'(?!'))",
            SyntaxKind::EscapedSingleQuote
        ),
        Matcher::regex(
            "unicode_double_quote",
            r#"(?s)U&".+?"(\s*UESCAPE\s*\'[^0-9A-Fa-f\'+\-\s)]\')?"#,
            SyntaxKind::UnicodeDoubleQuote
        ),
        Matcher::regex(
            "json_operator",
            r#"->>|#>>|->|#>|@>|<@|\?\|_|\?|\?&|#-"#,
            SyntaxKind::JsonOperator
        ),
        Matcher::string(
            "at",
            "@",
            SyntaxKind::At
        ),
        Matcher::regex(
            "bit_string_literal",
            r#"[bBxX]'[0-9a-fA-F]*'"#,
            SyntaxKind::BitStringLiteral
        ),
    ], "like_operator");

    postgres.insert_lexer_matchers(
        vec![
            Matcher::legacy(
                "meta_command",
                |s| s.starts_with("\\"),
                r"\\([^\\\r\n])+((\\\\)|(?=\n)|(?=\r\n))?",
                SyntaxKind::Comment,
            ),
            Matcher::regex(
                "dollar_numeric_literal",
                r"\$\d+",
                SyntaxKind::DollarNumericLiteral,
            ),
        ],
        "word",
    );

    postgres.patch_lexer_matchers(vec![
        Matcher::regex("inline_comment", r"(--)[^\n]*", SyntaxKind::InlineComment),
        Matcher::legacy(
            "single_quote",
            |s| s.starts_with("'"),
            r"(?s)('')+?(?!')|('.*?(?<!')(?:'')*'(?!'))",
            SyntaxKind::SingleQuote,
        ),
        Matcher::regex("double_quote", r#"(?s)".+?""#, SyntaxKind::DoubleQuote),
        Matcher::regex("word", r"[a-zA-Z_][0-9a-zA-Z_$]*", SyntaxKind::Word),
    ]);

    let keywords = postgres_keywords();
    let not_keywords = get_keywords(&keywords, "not-keyword");

    postgres
        .sets_mut("reserved_keywords")
        .extend(get_keywords(&keywords, "reserved"));
    postgres
        .sets_mut("unreserved_keywords")
        .extend(get_keywords(&keywords, "non-reserved"));

    postgres
        .sets_mut("reserved_keywords")
        .retain(|keyword| !not_keywords.contains(keyword));
    postgres
        .sets_mut("unreserved_keywords")
        .retain(|keyword| !not_keywords.contains(keyword));

    // Add datetime units
    postgres.sets_mut("datetime_units").extend([
        "CENTURY",
        "DECADE",
        "DOW",
        "DOY",
        "EPOCH",
        "ISODOW",
        "ISOYEAR",
        "MICROSECONDS",
        "MILLENNIUM",
        "MILLISECONDS",
        "TIMEZONE",
        "TIMEZONE_HOUR",
        "TIMEZONE_MINUTE",
    ]);

    // Set the bare functions
    postgres.sets_mut("bare_functions").extend([
        "CURRENT_TIMESTAMP",
        "CURRENT_TIME",
        "CURRENT_DATE",
        "LOCALTIME",
        "LOCALTIMESTAMP",
    ]);

    // Postgres doesn't have a dateadd function
    // Also according to https://www.postgresql.org/docs/14/functions-datetime.html
    // It quotes dateparts. So don't need this.
    postgres.sets_mut("date_part_function_name").clear();

    // In Postgres, UNNEST() returns a "value table", similar to BigQuery
    postgres
        .sets_mut("value_table_functions")
        .extend(["UNNEST", "GENERATE_SERIES"]);

    postgres.add([
        (
            "JsonOperatorSegment".into(),
            TypedParser::new(SyntaxKind::JsonOperator, SyntaxKind::BinaryOperator)
                .to_matchable()
                .into(),
        ),
        (
            "SimpleGeometryGrammar".into(),
            AnyNumberOf::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
                .to_matchable()
                .into(),
        ),
        (
            "MultilineConcatenateNewline".into(),
            TypedParser::new(SyntaxKind::Newline, SyntaxKind::Newline)
                .to_matchable()
                .into(),
        ),
        (
            "MultilineConcatenateDelimiterGrammar".into(),
            AnyNumberOf::new(vec![Ref::new("MultilineConcatenateNewline").to_matchable()])
                .config(|this| {
                    this.min_times(1);
                    this.disallow_gaps();
                })
                .to_matchable()
                .into(),
        ),
        (
            "NakedIdentifierFullSegment".into(),
            TypedParser::new(SyntaxKind::Word, SyntaxKind::NakedIdentifier)
                .to_matchable()
                .into(),
        ),
        (
            "PropertiesNakedIdentifierSegment".into(),
            TypedParser::new(SyntaxKind::Word, SyntaxKind::PropertiesNakedIdentifier)
                .to_matchable()
                .into(),
        ),
        (
            "SingleIdentifierFullGrammar".into(),
            one_of(vec![
                Ref::new("NakedIdentifierSegment").to_matchable(),
                Ref::new("QuotedIdentifierSegment").to_matchable(),
                Ref::new("NakedIdentifierFullSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "DefinitionArgumentValueGrammar".into(),
            one_of(vec![
                Ref::new("LiteralGrammar").to_matchable(),
                Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "CascadeRestrictGrammar".into(),
            one_of(vec![
                Ref::keyword("CASCADE").to_matchable(),
                Ref::keyword("RESTRICT").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "ExtendedTableReferenceGrammar".into(),
            one_of(vec![
                Ref::new("TableReferenceSegment").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ONLY").to_matchable(),
                    optionally_bracketed(vec![Ref::new("TableReferenceSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("StarSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "RightArrowSegment".into(),
            StringParser::new("=>", SyntaxKind::RightArrow)
                .to_matchable()
                .into(),
        ),
        (
            "OnKeywordAsIdentifierSegment".into(),
            StringParser::new("ON", SyntaxKind::NakedIdentifier)
                .to_matchable()
                .into(),
        ),
        (
            "DollarNumericLiteralSegment".into(),
            TypedParser::new(
                SyntaxKind::DollarNumericLiteral,
                SyntaxKind::DollarNumericLiteral,
            )
            .to_matchable()
            .into(),
        ),
        (
            "ForeignDataWrapperGrammar".into(),
            Sequence::new(vec![
                Ref::keyword("FOREIGN").to_matchable(),
                Ref::keyword("DATA").to_matchable(),
                Ref::keyword("WRAPPER").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "OptionsListGrammar".into(),
            Sequence::new(vec![
                Delimited::new(vec![
                    Ref::new("NakedIdentifierFullSegment").to_matchable(),
                    Ref::new("QuotedLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "OptionsGrammar".into(),
            Sequence::new(vec![
                Ref::keyword("OPTIONS").to_matchable(),
                Bracketed::new(vec![
                    AnyNumberOf::new(vec![Ref::new("OptionsListGrammar").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "CreateUserMappingGrammar".into(),
            Sequence::new(vec![
                Ref::keyword("CREATE").to_matchable(),
                Ref::keyword("USER").to_matchable(),
                Ref::keyword("MAPPING").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "SessionInformationUserFunctionsGrammar".into(),
            one_of(vec![
                Ref::keyword("USER").to_matchable(),
                Ref::keyword("CURRENT_ROLE").to_matchable(),
                Ref::keyword("CURRENT_USER").to_matchable(),
                Ref::keyword("SESSION_USER").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "ImportForeignSchemaGrammar".into(),
            Sequence::new(vec![
                Ref::keyword("IMPORT").to_matchable(),
                Ref::keyword("FOREIGN").to_matchable(),
                Ref::keyword("SCHEMA").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.add([
        (
            "LikeGrammar".into(),
            one_of(vec![
                Ref::keyword("LIKE").to_matchable(),
                Ref::keyword("ILIKE").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("SIMILAR").to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "StringBinaryOperatorGrammar".into(),
            one_of(vec![
                Ref::new("ConcatSegment").to_matchable(),
                Ref::keyword("COLLATE").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "ComparisonOperatorGrammar".into(),
            build_comparison_operator_grammar(false).into(),
        ),
        (
            "NakedIdentifierSegment".into(),
            SegmentGenerator::new(|dialect| {
                // Generate the anti-template from the set of reserved keywords
                let reserved_keywords = dialect.sets("reserved_keywords");
                let pattern = reserved_keywords.iter().join("|");
                let anti_template = format!("^({pattern})$");

                RegexParser::new(
                    r"([A-Z_]+|[0-9]+[A-Z_$])[A-Z0-9_$]*",
                    SyntaxKind::NakedIdentifier,
                )
                .anti_template(&anti_template)
                .to_matchable()
            })
            .into(),
        ),
        (
            "ParameterNameSegment".into(),
            RegexParser::new(r#"[A-Z_][A-Z0-9_$]*|\"[^\"]*\""#, SyntaxKind::Parameter)
                .to_matchable()
                .into(),
        ),
        (
            "FunctionNameIdentifierSegment".into(),
            RegexParser::new(r"[A-Z_][A-Z0-9_$]*", SyntaxKind::FunctionNameIdentifier)
                .to_matchable()
                .into(),
        ),
        (
            "FunctionContentsExpressionGrammar".into(),
            one_of(vec![
                Ref::new("ExpressionSegment").to_matchable(),
                Ref::new("NamedArgumentSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "QuotedLiteralSegment".into(),
            one_of(vec![
                Sequence::new(vec![
                    TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral)
                        .to_matchable(),
                    AnyNumberOf::new(vec![
                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
                        TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral)
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral)
                        .to_matchable(),
                    AnyNumberOf::new(vec![
                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
                        TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral)
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Delimited::new(vec![
                    TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral)
                        .to_matchable(),
                    AnyNumberOf::new(vec![
                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
                        TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral)
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Delimited::new(vec![
                    TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral)
                        .to_matchable(),
                    AnyNumberOf::new(vec![
                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
                        TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral)
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Delimited::new(vec![
                    TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral)
                        .to_matchable(),
                    AnyNumberOf::new(vec![
                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
                        TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral)
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "QuotedIdentifierSegment".into(),
            one_of(vec![
                TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier)
                    .to_matchable(),
                TypedParser::new(SyntaxKind::UnicodeDoubleQuote, SyntaxKind::QuotedLiteral)
                    .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "PostFunctionGrammar".into(),
            AnyNumberOf::new(vec![
                Ref::new("WithinGroupClauseSegment").to_matchable(),
                Ref::new("OverClauseSegment").to_matchable(),
                Ref::new("FilterClauseGrammar").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "BinaryOperatorGrammar".into(),
            one_of(vec![
                Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(),
                Ref::new("StringBinaryOperatorGrammar").to_matchable(),
                Ref::new("BooleanBinaryOperatorGrammar").to_matchable(),
                Ref::new("ComparisonOperatorGrammar").to_matchable(),
                Ref::new("JsonOperatorSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "FunctionParameterGrammar".into(),
            Sequence::new(vec![
                one_of(vec![
                    Ref::keyword("IN").to_matchable(),
                    Ref::keyword("OUT").to_matchable(),
                    Ref::keyword("INOUT").to_matchable(),
                    Ref::keyword("VARIADIC").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                one_of(vec![
                    Ref::new("DatatypeSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::new("ParameterNameSegment").to_matchable(),
                        Ref::new("DatatypeSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("DEFAULT").to_matchable(),
                        Ref::new("EqualsSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("ExpressionSegment").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "FrameClauseUnitGrammar".into(),
            one_of(vec![
                Ref::keyword("RANGE").to_matchable(),
                Ref::keyword("ROWS").to_matchable(),
                Ref::keyword("GROUPS").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "IsNullGrammar".into(),
            Ref::keyword("ISNULL").to_matchable().into(),
        ),
        (
            "NotNullGrammar".into(),
            Ref::keyword("NOTNULL").to_matchable().into(),
        ),
        (
            "JoinKeywordsGrammar".into(),
            Sequence::new(vec![
                Ref::keyword("JOIN").to_matchable(),
                Sequence::new(vec![Ref::keyword("LATERAL").to_matchable()])
                    .config(|this| this.optional())
                    .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "SelectClauseTerminatorGrammar".into(),
            one_of(vec![
                Ref::keyword("INTO").to_matchable(),
                Ref::keyword("FROM").to_matchable(),
                Ref::keyword("WHERE").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ORDER").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("LIMIT").to_matchable(),
                Ref::new("CommaSegment").to_matchable(),
                Ref::new("SetOperatorSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        // Assuming the existence of `ansi_dialect` in Rust and a way to manipulate its
        // grammar:
        (
            "LiteralGrammar".into(),
            postgres
                .grammar("LiteralGrammar")
                .copy(
                    Some(vec![
                        Ref::new("DollarNumericLiteralSegment").to_matchable(),
                        Ref::new("PsqlVariableGrammar").to_matchable(),
                    ]),
                    None,
                    Some(Ref::new("ArrayLiteralSegment").to_matchable()),
                    None,
                    Vec::new(),
                    false,
                )
                .into(),
        ),
        (
            "FromClauseTerminatorGrammar".into(),
            postgres
                .grammar("FromClauseTerminatorGrammar")
                .copy(
                    Some(vec![Ref::new("ForClauseSegment").to_matchable()]),
                    None,
                    None,
                    None,
                    Vec::new(),
                    false,
                )
                .into(),
        ),
        (
            "WhereClauseTerminatorGrammar".into(),
            one_of(vec![
                Ref::keyword("LIMIT").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("GROUP").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ORDER").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("HAVING").to_matchable(),
                Ref::keyword("QUALIFY").to_matchable(),
                Ref::keyword("WINDOW").to_matchable(),
                Ref::keyword("OVERLAPS").to_matchable(),
                Ref::keyword("RETURNING").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ON").to_matchable(),
                    Ref::keyword("CONFLICT").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("ForClauseSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "OrderByClauseTerminators".into(),
            one_of(vec![
                Ref::keyword("LIMIT").to_matchable(),
                Ref::keyword("HAVING").to_matchable(),
                Ref::keyword("QUALIFY").to_matchable(),
                Ref::keyword("WINDOW").to_matchable(),
                Ref::new("FrameClauseUnitGrammar").to_matchable(),
                Ref::keyword("SEPARATOR").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("DATA").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("ForClauseSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "AccessorGrammar".into(),
            AnyNumberOf::new(vec![
                Ref::new("ArrayAccessorSegment").to_matchable(),
                Ref::new("SemiStructuredAccessorSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "NonWithSelectableGrammar".into(),
            one_of(vec![
                Ref::new("SetExpressionSegment").to_matchable(),
                optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()])
                    .to_matchable(),
                Ref::new("NonSetSelectableGrammar").to_matchable(),
                Ref::new("UpdateStatementSegment").to_matchable(),
                Ref::new("InsertStatementSegment").to_matchable(),
                Ref::new("DeleteStatementSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "NonWithNonSelectableGrammar".into(),
            one_of(vec![]).to_matchable().into(),
        ),
    ]);

    postgres.add([
        (
            "OverlapSegment".into(),
            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
                Sequence::new(vec![
                    Ref::new("AmpersandSegment").to_matchable(),
                    Ref::new("AmpersandSegment").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "NotExtendRightSegment".into(),
            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
                Sequence::new(vec![
                    Ref::new("AmpersandSegment").to_matchable(),
                    Ref::new("RawGreaterThanSegment").to_matchable(),
                ])
                .allow_gaps(false)
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "NotExtendLeftSegment".into(),
            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
                Sequence::new(vec![
                    Ref::new("AmpersandSegment").to_matchable(),
                    Ref::new("RawLessThanSegment").to_matchable(),
                ])
                .allow_gaps(false)
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AdjacentSegment".into(),
            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
                Sequence::new(vec![
                    Ref::new("MinusSegment").to_matchable(),
                    Ref::new("PipeSegment").to_matchable(),
                    Ref::new("MinusSegment").to_matchable(),
                ])
                .allow_gaps(false)
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.add([(
        "PsqlVariableGrammar".into(),
        NodeMatcher::new(SyntaxKind::PsqlVariable, |_| {
            Sequence::new(vec![
                optionally_bracketed(vec![
                    Ref::new("ColonSegment").to_matchable(),
                    one_of(vec![
                        Ref::new("ParameterNameSegment").to_matchable(),
                        Ref::new("QuotedLiteralSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "ArrayAccessorSegment",
        Bracketed::new(vec![
            one_of(vec![
                // These three are for a single element access: [n]
                Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
                Ref::new("ExpressionSegment").to_matchable(),
                // This is for slice access: [n:m], [:m], [n:], and [:]
                Sequence::new(vec![
                    one_of(vec![
                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
                        Ref::new("NumericLiteralSegment").to_matchable(),
                        Ref::new("ExpressionSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::new("SliceSegment").to_matchable(),
                    one_of(vec![
                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
                        Ref::new("NumericLiteralSegment").to_matchable(),
                        Ref::new("ExpressionSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .config(|this| {
            this.bracket_type("square");
        })
        .to_matchable(),
    );

    postgres.add([(
        "DateTimeTypeIdentifier".into(),
        NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_| {
            one_of(vec![
                Ref::keyword("DATE").to_matchable(),
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("TIME").to_matchable(),
                        Ref::keyword("TIMESTAMP").to_matchable(),
                    ])
                    .to_matchable(),
                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
                        .config(|this| this.optional())
                        .to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("WITH").to_matchable(),
                            Ref::keyword("WITHOUT").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("TIME").to_matchable(),
                        Ref::keyword("ZONE").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("INTERVAL").to_matchable(),
                        Ref::keyword("TIMETZ").to_matchable(),
                        Ref::keyword("TIMESTAMPTZ").to_matchable(),
                    ])
                    .to_matchable(),
                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
                        .config(|this| this.optional())
                        .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([(
        "DateTimeLiteralGrammar".into(),
        NodeMatcher::new(SyntaxKind::DatetimeLiteral, |_| {
            Sequence::new(vec![
                Ref::new("DateTimeTypeIdentifier").optional().to_matchable(),
                Ref::new("QuotedLiteralSegment").to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar("DatatypeSegment", build_datatype_segment_grammar(false));

    postgres.replace_grammar("ArrayTypeSegment", Ref::keyword("ARRAY").to_matchable());

    postgres.add([(
        "IndexAccessMethodSegment".into(),
        NodeMatcher::new(SyntaxKind::IndexAccessMethod, |_| {
            Ref::new("SingleIdentifierGrammar").to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([(
        "OperatorClassReferenceSegment".into(),
        NodeMatcher::new(SyntaxKind::OperatorClassReference, |postgres| {
            postgres
                .grammar("ObjectReferenceSegment")
                .match_grammar(postgres)
                .unwrap()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([
        (
            "DefinitionParameterSegment".into(),
            NodeMatcher::new(SyntaxKind::DefinitionParameter, |_| {
                Sequence::new(vec![
                    Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::new("EqualsSegment").to_matchable(),
                        Ref::new("DefinitionArgumentValueGrammar")
                            .optional()
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DefinitionParametersSegment".into(),
            NodeMatcher::new(SyntaxKind::DefinitionParameters, |_| {
                Bracketed::new(vec![
                    Delimited::new(vec![Ref::new("DefinitionParameterSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "CreateCastStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            Ref::keyword("CAST").to_matchable(),
            Bracketed::new(vec![
                Sequence::new(vec![
                    Ref::new("DatatypeSegment").to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    Ref::new("DatatypeSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("FUNCTION").to_matchable(),
                    Ref::new("FunctionNameSegment").to_matchable(),
                    Ref::new("FunctionParameterListGrammar")
                        .optional()
                        .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITHOUT").to_matchable(),
                    Ref::keyword("FUNCTION").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("INOUT").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("AS").to_matchable(),
                    Ref::keyword("ASSIGNMENT").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("AS").to_matchable(),
                    Ref::keyword("IMPLICIT").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "DropCastStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DROP").to_matchable(),
            Ref::keyword("CAST").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("IF").to_matchable(),
                Ref::keyword("EXISTS").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Bracketed::new(vec![
                Sequence::new(vec![
                    Ref::new("DatatypeSegment").to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    Ref::new("DatatypeSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "RelationOptionSegment".into(),
            NodeMatcher::new(SyntaxKind::RelationOption, |_| {
                Sequence::new(vec![
                    Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::new("DotSegment").to_matchable(),
                        Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::new("EqualsSegment").to_matchable(),
                        Ref::new("DefinitionArgumentValueGrammar")
                            .optional()
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "RelationOptionsSegment".into(),
            NodeMatcher::new(SyntaxKind::RelationOptions, |_| {
                Bracketed::new(vec![
                    Delimited::new(vec![Ref::new("RelationOptionSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "CreateFunctionStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("OR").to_matchable(),
                Ref::keyword("REPLACE").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Ref::new("TemporaryGrammar").optional().to_matchable(),
            Ref::keyword("FUNCTION").to_matchable(),
            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
            Ref::new("FunctionNameSegment").to_matchable(),
            Ref::new("FunctionParameterListGrammar").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("RETURNS").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("TABLE").to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                one_of(vec![
                                    Ref::new("DatatypeSegment").to_matchable(),
                                    Sequence::new(vec![
                                        Ref::new("ColumnReferenceSegment").to_matchable(),
                                        Ref::new("DatatypeSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SETOF").to_matchable(),
                        Ref::new("DatatypeSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("DatatypeSegment").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Ref::new("FunctionDefinitionGrammar").to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "DropFunctionStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("FUNCTION").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("FunctionNameSegment").to_matchable(),
                            Ref::new("FunctionParameterListGrammar")
                                .optional()
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterFunctionStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterFunctionStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("FUNCTION").to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("FunctionNameSegment").to_matchable(),
                            Ref::new("FunctionParameterListGrammar")
                                .optional()
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::new("AlterFunctionActionSegment")
                            .optional()
                            .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("FunctionNameSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("SchemaReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                one_of(vec![
                                    Ref::new("ParameterNameSegment").to_matchable(),
                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NO").optional().to_matchable(),
                            Ref::keyword("DEPENDS").to_matchable(),
                            Ref::keyword("ON").to_matchable(),
                            Ref::keyword("EXTENSION").to_matchable(),
                            Ref::new("ExtensionReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterFunctionActionSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterFunctionActionSegment, |_| {
                Sequence::new(vec![
                    one_of(vec![
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("CALLED").to_matchable(),
                                Ref::keyword("ON").to_matchable(),
                                Ref::keyword("NULL").to_matchable(),
                                Ref::keyword("INPUT").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("RETURNS").to_matchable(),
                                Ref::keyword("NULL").to_matchable(),
                                Ref::keyword("ON").to_matchable(),
                                Ref::keyword("NULL").to_matchable(),
                                Ref::keyword("INPUT").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("STRICT").to_matchable(),
                        ])
                        .to_matchable(),
                        one_of(vec![
                            Ref::keyword("IMMUTABLE").to_matchable(),
                            Ref::keyword("STABLE").to_matchable(),
                            Ref::keyword("VOLATILE").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NOT").optional().to_matchable(),
                            Ref::keyword("LEAKPROOF").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("EXTERNAL").optional().to_matchable(),
                            Ref::keyword("SECURITY").to_matchable(),
                            one_of(vec![
                                Ref::keyword("DEFINER").to_matchable(),
                                Ref::keyword("INVOKER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("PARALLEL").to_matchable(),
                            one_of(vec![
                                Ref::keyword("UNSAFE").to_matchable(),
                                Ref::keyword("RESTRICTED").to_matchable(),
                                Ref::keyword("SAFE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("COST").to_matchable(),
                            Ref::new("NumericLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ROWS").to_matchable(),
                            Ref::new("NumericLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SUPPORT").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    one_of(vec![
                                        Ref::keyword("TO").to_matchable(),
                                        Ref::new("EqualsSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    one_of(vec![
                                        Ref::new("LiteralGrammar").to_matchable(),
                                        Ref::new("NakedIdentifierSegment").to_matchable(),
                                        Ref::keyword("DEFAULT").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FROM").to_matchable(),
                                    Ref::keyword("CURRENT").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RESET").to_matchable(),
                            one_of(vec![
                                Ref::keyword("ALL").to_matchable(),
                                Ref::new("ParameterNameSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("RESTRICT").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterProcedureActionSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterProcedureActionSegment, |_| {
                Sequence::new(vec![
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("EXTERNAL").optional().to_matchable(),
                            Ref::keyword("SECURITY").to_matchable(),
                            one_of(vec![
                                Ref::keyword("DEFINER").to_matchable(),
                                Ref::keyword("INVOKER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    one_of(vec![
                                        Ref::keyword("TO").to_matchable(),
                                        Ref::new("EqualsSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    one_of(vec![
                                        Ref::new("LiteralGrammar").to_matchable(),
                                        Ref::new("NakedIdentifierSegment").to_matchable(),
                                        Ref::keyword("DEFAULT").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FROM").to_matchable(),
                                    Ref::keyword("CURRENT").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RESET").to_matchable(),
                            one_of(vec![
                                Ref::keyword("ALL").to_matchable(),
                                Ref::new("ParameterNameSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("RESTRICT").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterProcedureStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("PROCEDURE").to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("FunctionNameSegment").to_matchable(),
                            Ref::new("FunctionParameterListGrammar")
                                .optional()
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::new("AlterProcedureActionSegment")
                            .optional()
                            .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("FunctionNameSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("SchemaReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    one_of(vec![
                                        Ref::keyword("TO").to_matchable(),
                                        Ref::new("EqualsSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Delimited::new(vec![
                                        one_of(vec![
                                            Ref::new("ParameterNameSegment").to_matchable(),
                                            Ref::new("LiteralGrammar").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FROM").to_matchable(),
                                    Ref::keyword("CURRENT").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                one_of(vec![
                                    Ref::new("ParameterNameSegment").to_matchable(),
                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NO").optional().to_matchable(),
                            Ref::keyword("DEPENDS").to_matchable(),
                            Ref::keyword("ON").to_matchable(),
                            Ref::keyword("EXTENSION").to_matchable(),
                            Ref::new("ExtensionReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateProcedureStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OR").to_matchable(),
                        Ref::keyword("REPLACE").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::keyword("PROCEDURE").to_matchable(),
                    Ref::new("FunctionNameSegment").to_matchable(),
                    Ref::new("FunctionParameterListGrammar").to_matchable(),
                    Ref::new("FunctionDefinitionGrammar").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DropProcedureStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("PROCEDURE").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("FunctionNameSegment").to_matchable(),
                            Ref::new("FunctionParameterListGrammar")
                                .optional()
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("CASCADE").to_matchable(),
                        Ref::keyword("RESTRICT").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "WellKnownTextGeometrySegment".into(),
            NodeMatcher::new(SyntaxKind::WktGeometryType, |_| {
                let geometry_type_keywords = POSTGRES_POSTGIS_DATATYPE_KEYWORDS
                    .iter()
                    .map(|(kw, _)| Ref::keyword(*kw).to_matchable())
                    .collect_vec();

                let mut geometry_type_keywords0 = geometry_type_keywords.clone();
                geometry_type_keywords0.extend(
                    ["GEOMETRY", "GEOGRAPHY"]
                        .into_iter()
                        .map(|it| Ref::keyword(it).to_matchable()),
                );

                one_of(vec![
                    Sequence::new(vec![
                        one_of(geometry_type_keywords.clone()).to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                optionally_bracketed(vec![
                                    Delimited::new(vec![
                                        Ref::new("SimpleGeometryGrammar").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Bracketed::new(vec![
                                    Delimited::new(vec![
                                        Bracketed::new(vec![
                                            Delimited::new(vec![
                                                Ref::new("SimpleGeometryGrammar").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::new("WellKnownTextGeometrySegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("GEOMETRY").to_matchable(),
                            Ref::keyword("GEOGRAPHY").to_matchable(),
                        ])
                        .to_matchable(),
                        Bracketed::new(vec![
                            Sequence::new(vec![
                                one_of(geometry_type_keywords0).to_matchable(),
                                Ref::new("CommaSegment").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "SemiStructuredAccessorSegment".into(),
            NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| {
                Sequence::new(vec![
                    Ref::new("DotSegment").to_matchable(),
                    Ref::new("SingleIdentifierGrammar").to_matchable(),
                    Ref::new("ArrayAccessorSegment").optional().to_matchable(),
                    AnyNumberOf::new(vec![
                        Sequence::new(vec![
                            Ref::new("DotSegment").to_matchable(),
                            Ref::new("SingleIdentifierGrammar").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::new("ArrayAccessorSegment").optional().to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "FunctionDefinitionGrammar",
        Sequence::new(vec![
            AnyNumberOf::new(vec![
                Ref::new("LanguageClauseSegment").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("TRANSFORM").to_matchable(),
                    Ref::keyword("FOR").to_matchable(),
                    Ref::keyword("TYPE").to_matchable(),
                    Ref::new("ParameterNameSegment").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("WINDOW").to_matchable(),
                one_of(vec![
                    Ref::keyword("IMMUTABLE").to_matchable(),
                    Ref::keyword("STABLE").to_matchable(),
                    Ref::keyword("VOLATILE").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NOT").optional().to_matchable(),
                    Ref::keyword("LEAKPROOF").to_matchable(),
                ])
                .to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("CALLED").to_matchable(),
                        Ref::keyword("ON").to_matchable(),
                        Ref::keyword("NULL").to_matchable(),
                        Ref::keyword("INPUT").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RETURNS").to_matchable(),
                        Ref::keyword("NULL").to_matchable(),
                        Ref::keyword("ON").to_matchable(),
                        Ref::keyword("NULL").to_matchable(),
                        Ref::keyword("INPUT").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("STRICT").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("EXTERNAL").optional().to_matchable(),
                    Ref::keyword("SECURITY").to_matchable(),
                    one_of(vec![
                        Ref::keyword("INVOKER").to_matchable(),
                        Ref::keyword("DEFINER").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("PARALLEL").to_matchable(),
                    one_of(vec![
                        Ref::keyword("UNSAFE").to_matchable(),
                        Ref::keyword("RESTRICTED").to_matchable(),
                        Ref::keyword("SAFE").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("COST").to_matchable(),
                    Ref::new("NumericLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ROWS").to_matchable(),
                    Ref::new("NumericLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("SUPPORT").to_matchable(),
                    Ref::new("ParameterNameSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("SET").to_matchable(),
                    Ref::new("ParameterNameSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            one_of(vec![
                                Ref::keyword("TO").to_matchable(),
                                Ref::new("EqualsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Delimited::new(vec![
                                one_of(vec![
                                    Ref::new("ParameterNameSegment").to_matchable(),
                                    Ref::new("LiteralGrammar").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("FROM").to_matchable(),
                            Ref::keyword("CURRENT").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("AS").to_matchable(),
                    one_of(vec![
                        Ref::new("QuotedLiteralSegment").to_matchable(),
                        Sequence::new(vec![
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                            Ref::new("CommaSegment").to_matchable(),
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("WITH").to_matchable(),
                Bracketed::new(vec![
                    Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "IntoClauseSegment".into(),
            NodeMatcher::new(SyntaxKind::IntoClause, |_| {
                Sequence::new(vec![
                    Ref::keyword("INTO").to_matchable(),
                    one_of(vec![
                        Ref::keyword("TEMPORARY").to_matchable(),
                        Ref::keyword("TEMP").to_matchable(),
                        Ref::keyword("UNLOGGED").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::keyword("TABLE").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ForClauseSegment".into(),
            NodeMatcher::new(SyntaxKind::ForClause, |_| {
                Sequence::new(vec![
                    Ref::keyword("FOR").to_matchable(),
                    one_of(vec![
                        Ref::keyword("UPDATE").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NO").to_matchable(),
                            Ref::keyword("KEY").to_matchable(),
                            Ref::keyword("UPDATE").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("SHARE").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("KEY").to_matchable(),
                            Ref::keyword("SHARE").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OF").to_matchable(),
                        Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("NOWAIT").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SKIP").to_matchable(),
                            Ref::keyword("LOCKED").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "UnorderedSelectStatementSegment",
        ansi::get_unordered_select_statement_segment_grammar().copy(
            Some(vec![
                Ref::new("IntoClauseSegment").optional().to_matchable(),
            ]),
            None,
            Some(Ref::new("FromClauseSegment").optional().to_matchable()),
            None,
            vec![
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("NO").optional().to_matchable(),
                    Ref::keyword("DATA").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ON").to_matchable(),
                    Ref::keyword("CONFLICT").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("RETURNING").to_matchable(),
                Ref::new("WithCheckOptionSegment").to_matchable(),
            ],
            false,
        ),
    );

    postgres.replace_grammar(
        "SelectStatementSegment",
        postgres
            .grammar("UnorderedSelectStatementSegment")
            .match_grammar(&postgres)
            .unwrap()
            .copy(
                Some(vec![
                    Ref::new("OrderByClauseSegment").optional().to_matchable(),
                    Ref::new("LimitClauseSegment").optional().to_matchable(),
                    Ref::new("NamedWindowSegment").optional().to_matchable(),
                ]),
                None,
                None,
                None,
                vec![],
                false,
            )
            .copy(
                Some(vec![Ref::new("ForClauseSegment").optional().to_matchable()]),
                None,
                Some(Ref::new("LimitClauseSegment").optional().to_matchable()),
                None,
                vec![
                    Ref::new("SetOperatorSegment").to_matchable(),
                    Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
                    Ref::new("WithDataClauseSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ON").to_matchable(),
                        Ref::keyword("CONFLICT").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("RETURNING").to_matchable(),
                    Ref::new("WithCheckOptionSegment").to_matchable(),
                ],
                true,
            ),
    );

    postgres.replace_grammar(
        "SelectClauseSegment",
        Sequence::new(vec![
            Ref::keyword("SELECT").to_matchable(),
            Ref::new("SelectClauseModifierSegment")
                .optional()
                .to_matchable(),
            MetaSegment::indent().to_matchable(),
            Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()])
                .config(|this| {
                    this.optional();
                    this.allow_trailing = true;
                })
                .to_matchable(),
        ])
        .config(|this| {
            this.terminators = vec![
                Ref::keyword("INTO").to_matchable(),
                Ref::keyword("FROM").to_matchable(),
                Ref::keyword("WHERE").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ORDER").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("LIMIT").to_matchable(),
                Ref::keyword("OVERLAPS").to_matchable(),
                Ref::new("SetOperatorSegment").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("NO").optional().to_matchable(),
                    Ref::keyword("DATA").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("WithCheckOptionSegment").to_matchable(),
            ];
            this.parse_mode(ParseMode::GreedyOnceStarted);
        })
        .to_matchable(),
    );

    postgres.replace_grammar(
        "SelectClauseModifierSegment",
        one_of(vec![
            Sequence::new(vec![
                Ref::keyword("DISTINCT").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ON").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable(),
            Ref::keyword("ALL").to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "WithinGroupClauseSegment".into(),
            NodeMatcher::new(SyntaxKind::WithingroupClause, |_| {
                Sequence::new(vec![
                    Ref::keyword("WITHIN").to_matchable(),
                    Ref::keyword("GROUP").to_matchable(),
                    Bracketed::new(vec![
                        Ref::new("OrderByClauseSegment").optional().to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "GroupByClauseSegment".into(),
            NodeMatcher::new(SyntaxKind::GroupbyClause, |_| {
                Sequence::new(vec![
                    Ref::keyword("GROUP").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                    MetaSegment::indent().to_matchable(),
                    Delimited::new(vec![
                        one_of(vec![
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                            Ref::new("NumericLiteralSegment").to_matchable(),
                            Ref::new("CubeRollupClauseSegment").to_matchable(),
                            Ref::new("GroupingSetsClauseSegment").to_matchable(),
                            Ref::new("ExpressionSegment").to_matchable(),
                            Bracketed::new(vec![]).to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| {
                        this.terminators = vec![
                            Sequence::new(vec![
                                Ref::keyword("ORDER").to_matchable(),
                                Ref::keyword("BY").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("LIMIT").to_matchable(),
                            Ref::keyword("HAVING").to_matchable(),
                            Ref::keyword("QUALIFY").to_matchable(),
                            Ref::keyword("WINDOW").to_matchable(),
                            Ref::new("SetOperatorSegment").to_matchable(),
                        ];
                    })
                    .to_matchable(),
                    MetaSegment::dedent().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "CreateRoleStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            one_of(vec![
                Ref::keyword("ROLE").to_matchable(),
                Ref::keyword("USER").to_matchable(),
            ])
            .to_matchable(),
            Ref::new("RoleReferenceSegment").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("WITH").optional().to_matchable(),
                any_set_of(vec![
                    one_of(vec![
                        Ref::keyword("SUPERUSER").to_matchable(),
                        Ref::keyword("NOSUPERUSER").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("CREATEDB").to_matchable(),
                        Ref::keyword("NOCREATEDB").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("CREATEROLE").to_matchable(),
                        Ref::keyword("NOCREATEROLE").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("INHERIT").to_matchable(),
                        Ref::keyword("NOINHERIT").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("LOGIN").to_matchable(),
                        Ref::keyword("NOLOGIN").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("REPLICATION").to_matchable(),
                        Ref::keyword("NOREPLICATION").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("BYPASSRLS").to_matchable(),
                        Ref::keyword("NOBYPASSRLS").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("CONNECTION").to_matchable(),
                        Ref::keyword("LIMIT").to_matchable(),
                        Ref::new("NumericLiteralSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("PASSWORD").to_matchable(),
                        one_of(vec![
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                            Ref::keyword("NULL").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("VALID").to_matchable(),
                        Ref::keyword("UNTIL").to_matchable(),
                        Ref::new("QuotedLiteralSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("IN").to_matchable(),
                        Ref::keyword("ROLE").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("IN").to_matchable(),
                        Ref::keyword("GROUP").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ROLE").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ADMIN").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USER").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SYSID").to_matchable(),
                        Ref::new("NumericLiteralSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "AlterRoleStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::AlterRoleStatement, |_| {
            Sequence::new(vec![
                Ref::keyword("ALTER").to_matchable(),
                one_of(vec![
                    Ref::keyword("ROLE").to_matchable(),
                    Ref::keyword("USER").to_matchable(),
                ])
                .to_matchable(),
                one_of(vec![
                    // role_specification
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                            Ref::new("RoleReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("WITH").optional().to_matchable(),
                        any_set_of(vec![
                            one_of(vec![
                                Ref::keyword("SUPERUSER").to_matchable(),
                                Ref::keyword("NOSUPERUSER").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("CREATEDB").to_matchable(),
                                Ref::keyword("NOCREATEDB").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("CREATEROLE").to_matchable(),
                                Ref::keyword("NOCREATEROLE").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("INHERIT").to_matchable(),
                                Ref::keyword("NOINHERIT").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("LOGIN").to_matchable(),
                                Ref::keyword("NOLOGIN").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("REPLICATION").to_matchable(),
                                Ref::keyword("NOREPLICATION").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("BYPASSRLS").to_matchable(),
                                Ref::keyword("NOBYPASSRLS").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("CONNECTION").to_matchable(),
                                Ref::keyword("LIMIT").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ENCRYPTED").optional().to_matchable(),
                                Ref::keyword("PASSWORD").to_matchable(),
                                one_of(vec![
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                    Ref::keyword("NULL").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("VALID").to_matchable(),
                                Ref::keyword("UNTIL").to_matchable(),
                                Ref::new("QuotedLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    // name only
                    Sequence::new(vec![
                        Ref::new("RoleReferenceSegment").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("RoleReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    // role_specification | all
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                            Ref::keyword("ALL").to_matchable(),
                            Ref::new("RoleReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("IN").to_matchable(),
                            Ref::keyword("DATABASE").to_matchable(),
                            Ref::new("DatabaseReferenceSegment").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::new("ParameterNameSegment").to_matchable(),
                                one_of(vec![
                                    Sequence::new(vec![
                                        one_of(vec![
                                            Ref::keyword("TO").to_matchable(),
                                            Ref::new("EqualsSegment").to_matchable(),
                                        ])
                                        .to_matchable(),
                                        one_of(vec![
                                            Ref::keyword("DEFAULT").to_matchable(),
                                            Delimited::new(vec![
                                                Ref::new("LiteralGrammar").to_matchable(),
                                                Ref::new("NakedIdentifierSegment").to_matchable(),
                                                Ref::new("OnKeywordAsIdentifierSegment")
                                                    .to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("FROM").to_matchable(),
                                        Ref::keyword("CURRENT").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("RESET").to_matchable(),
                                one_of(vec![
                                    Ref::new("ParameterNameSegment").to_matchable(),
                                    Ref::keyword("ALL").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "ExplainStatementSegment",
        Sequence::new(vec![
            Ref::keyword("EXPLAIN").to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("ANALYZE").optional().to_matchable(),
                        Ref::keyword("ANALYSE").optional().to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("VERBOSE").optional().to_matchable(),
                ])
                .to_matchable(),
                Bracketed::new(vec![
                    Delimited::new(vec![Ref::new("ExplainOptionSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            ansi::explainable_stmt().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "ExplainOptionSegment".into(),
        NodeMatcher::new(SyntaxKind::ExplainOption, |_| {
            one_of(vec![
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("ANALYZE").to_matchable(),
                        Ref::keyword("ANALYSE").to_matchable(),
                        Ref::keyword("VERBOSE").to_matchable(),
                        Ref::keyword("COSTS").to_matchable(),
                        Ref::keyword("SETTINGS").to_matchable(),
                        Ref::keyword("BUFFERS").to_matchable(),
                        Ref::keyword("WAL").to_matchable(),
                        Ref::keyword("TIMING").to_matchable(),
                        Ref::keyword("SUMMARY").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("FORMAT").to_matchable(),
                    one_of(vec![
                        Ref::keyword("TEXT").to_matchable(),
                        Ref::keyword("XML").to_matchable(),
                        Ref::keyword("JSON").to_matchable(),
                        Ref::keyword("YAML").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "CreateSchemaStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            Ref::keyword("SCHEMA").to_matchable(),
            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::new("SchemaReferenceSegment").optional().to_matchable(),
                    Ref::keyword("AUTHORIZATION").to_matchable(),
                    Ref::new("RoleReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("SchemaReferenceSegment").to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "CreateTableStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("GLOBAL").to_matchable(),
                        Ref::keyword("LOCAL").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::new("TemporaryGrammar").optional().to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("UNLOGGED").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Ref::keyword("TABLE").to_matchable(),
            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            one_of(vec![
                                Sequence::new(vec![
                                    Ref::new("ColumnReferenceSegment").to_matchable(),
                                    Ref::new("DatatypeSegment").to_matchable(),
                                    AnyNumberOf::new(vec![
                                        one_of(vec![
                                            Ref::new("ColumnConstraintSegment").to_matchable(),
                                            Sequence::new(vec![
                                                Ref::keyword("COLLATE").to_matchable(),
                                                Ref::new("CollationReferenceSegment")
                                                    .to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::new("TableConstraintSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("LIKE").to_matchable(),
                                    Ref::new("TableReferenceSegment").to_matchable(),
                                    AnyNumberOf::new(vec![
                                        Ref::new("LikeOptionSegment").to_matchable(),
                                    ])
                                    .config(|this| this.optional())
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("INHERITS").to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("OF").to_matchable(),
                    Ref::new("ParameterNameSegment").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            Sequence::new(vec![
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("WITH").to_matchable(),
                                    Ref::keyword("OPTIONS").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                AnyNumberOf::new(vec![
                                    Ref::new("ColumnConstraintSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::new("TableConstraintSegment").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("PARTITION").to_matchable(),
                    Ref::keyword("OF").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            Sequence::new(vec![
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("WITH").to_matchable(),
                                    Ref::keyword("OPTIONS").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                AnyNumberOf::new(vec![
                                    Ref::new("ColumnConstraintSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::new("TableConstraintSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("FOR").to_matchable(),
                            Ref::keyword("VALUES").to_matchable(),
                            Ref::new("PartitionBoundSpecSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("DEFAULT").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            AnyNumberOf::new(vec![
                Sequence::new(vec![
                    Ref::keyword("PARTITION").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                    one_of(vec![
                        Ref::keyword("RANGE").to_matchable(),
                        Ref::keyword("LIST").to_matchable(),
                        Ref::keyword("HASH").to_matchable(),
                    ])
                    .to_matchable(),
                    Bracketed::new(vec![
                        AnyNumberOf::new(vec![
                            Delimited::new(vec![
                                Sequence::new(vec![
                                    one_of(vec![
                                        Ref::new("ColumnReferenceSegment").to_matchable(),
                                        Ref::new("FunctionSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    AnyNumberOf::new(vec![
                                        Sequence::new(vec![
                                            Ref::keyword("COLLATE").to_matchable(),
                                            Ref::new("CollationReferenceSegment").to_matchable(),
                                        ])
                                        .config(|this| this.optional())
                                        .to_matchable(),
                                        Ref::new("ParameterNameSegment").optional().to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("USING").to_matchable(),
                    Ref::new("ParameterNameSegment").to_matchable(),
                ])
                .to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("RelationOptionsSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITHOUT").to_matchable(),
                        Ref::keyword("OIDS").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ON").to_matchable(),
                    Ref::keyword("COMMIT").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("PRESERVE").to_matchable(),
                            Ref::keyword("ROWS").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("DELETE").to_matchable(),
                            Ref::keyword("ROWS").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("DROP").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("TABLESPACE").to_matchable(),
                    Ref::new("TablespaceReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "CreateTableAsStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_| {
            Sequence::new(vec![
                Ref::keyword("CREATE").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("GLOBAL").to_matchable(),
                            Ref::keyword("LOCAL").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        Ref::new("TemporaryGrammar").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("UNLOGGED").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                Ref::keyword("TABLE").to_matchable(),
                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                Ref::new("TableReferenceSegment").to_matchable(),
                AnyNumberOf::new(vec![
                    Sequence::new(vec![
                        Bracketed::new(vec![
                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USING").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("WITH").to_matchable(),
                            Bracketed::new(vec![
                                Delimited::new(vec![
                                    Sequence::new(vec![
                                        Ref::new("ParameterNameSegment").to_matchable(),
                                        Sequence::new(vec![
                                            Ref::new("EqualsSegment").to_matchable(),
                                            one_of(vec![
                                                Ref::new("LiteralGrammar").to_matchable(),
                                                Ref::new("NakedIdentifierSegment").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .config(|this| this.optional())
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("WITHOUT").to_matchable(),
                            Ref::keyword("OIDS").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ON").to_matchable(),
                        Ref::keyword("COMMIT").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("PRESERVE").to_matchable(),
                                Ref::keyword("ROWS").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("DELETE").to_matchable(),
                                Ref::keyword("ROWS").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("DROP").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("AS").to_matchable(),
                one_of(vec![
                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
                        .to_matchable(),
                    optionally_bracketed(vec![
                        Sequence::new(vec![
                            Ref::keyword("TABLE").to_matchable(),
                            Ref::new("TableReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("ValuesClauseSegment").to_matchable(),
                    optionally_bracketed(vec![
                        Sequence::new(vec![
                            Ref::keyword("EXECUTE").to_matchable(),
                            Ref::new("FunctionSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Ref::new("WithDataClauseSegment").optional().to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    // A `ALTER AGGREGATE` statement.
    // https://www.postgresql.org/docs/current/sql-alteraggregate.html
    postgres.add([(
        "AlterAggregateStatementSegment".into(),
        Sequence::new(vec![
            Ref::keyword("ALTER").to_matchable(),
            Ref::keyword("AGGREGATE").to_matchable(),
            Ref::new("ObjectReferenceSegment").to_matchable(),
            Bracketed::new(vec![
                one_of(vec![
                    Ref::new("FunctionParameterListGrammar").to_matchable(),
                    Anything::new().to_matchable(),
                    Ref::new("StarSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("RENAME").to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    Ref::new("FunctionNameSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("OWNER").to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    one_of(vec![
                        Ref::keyword("CURRENT_ROLE").to_matchable(),
                        Ref::keyword("CURRENT_USER").to_matchable(),
                        Ref::keyword("SESSION_USER").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("SET").to_matchable(),
                    Ref::keyword("SCHEMA").to_matchable(),
                    Ref::new("SchemaReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "AlterTableStatementSegment",
        Sequence::new(vec![
            Ref::keyword("ALTER").to_matchable(),
            Ref::keyword("TABLE").to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Ref::keyword("ONLY").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("StarSegment").optional().to_matchable(),
                    one_of(vec![
                        Delimited::new(vec![Ref::new("AlterTableActionSegment").to_matchable()])
                            .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("COLUMN").optional().to_matchable(),
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("CONSTRAINT").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("TableReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("SchemaReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ATTACH").to_matchable(),
                            Ref::keyword("PARTITION").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    Ref::keyword("FOR").to_matchable(),
                                    Ref::keyword("VALUES").to_matchable(),
                                    Ref::new("PartitionBoundSpecSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("DETACH").to_matchable(),
                            Ref::keyword("PARTITION").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                            Ref::keyword("CONCURRENTLY").optional().to_matchable(),
                            Ref::keyword("FINALIZE").optional().to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("ALL").to_matchable(),
                    Ref::keyword("IN").to_matchable(),
                    Ref::keyword("TABLESPACE").to_matchable(),
                    Ref::new("TablespaceReferenceSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OWNED").to_matchable(),
                        Ref::keyword("BY").to_matchable(),
                        Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
                            .config(|this| this.optional())
                            .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("SET").to_matchable(),
                    Ref::keyword("TABLESPACE").to_matchable(),
                    Ref::new("TablespaceReferenceSegment").to_matchable(),
                    Ref::keyword("NOWAIT").optional().to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "AlterTableActionSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_| {
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("ADD").to_matchable(),
                        Ref::keyword("COLUMN").optional().to_matchable(),
                        Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                        Ref::new("ColumnReferenceSegment").to_matchable(),
                        Ref::new("DatatypeSegment").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("COLLATE").to_matchable(),
                            Ref::new("CollationReferenceSegment").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("DROP").to_matchable(),
                        Ref::keyword("COLUMN").optional().to_matchable(),
                        Ref::new("IfExistsGrammar").optional().to_matchable(),
                        Ref::new("ColumnReferenceSegment").to_matchable(),
                        Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ALTER").to_matchable(),
                        Ref::keyword("COLUMN").optional().to_matchable(),
                        Ref::new("ColumnReferenceSegment").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Sequence::new(vec![
                                    Ref::keyword("SET").to_matchable(),
                                    Ref::keyword("DATA").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                Ref::keyword("TYPE").to_matchable(),
                                Ref::new("DatatypeSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("COLLATE").to_matchable(),
                                    Ref::new("CollationReferenceSegment").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("USING").to_matchable(),
                                    one_of(vec![Ref::new("ExpressionSegment").to_matchable()])
                                        .to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                                one_of(vec![
                                    Ref::new("LiteralGrammar").to_matchable(),
                                    Ref::new("FunctionSegment").to_matchable(),
                                    Ref::new("BareFunctionSegment").to_matchable(),
                                    Ref::new("ExpressionSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("DROP").to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                one_of(vec![
                                    Ref::keyword("SET").to_matchable(),
                                    Ref::keyword("DROP").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                Ref::keyword("NOT").to_matchable(),
                                Ref::keyword("NULL").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("DROP").to_matchable(),
                                Ref::keyword("EXPRESSION").to_matchable(),
                                Ref::new("IfExistsGrammar").optional().to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ADD").to_matchable(),
                                Ref::keyword("GENERATED").to_matchable(),
                                one_of(vec![
                                    Ref::keyword("ALWAYS").to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("BY").to_matchable(),
                                        Ref::keyword("DEFAULT").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::keyword("AS").to_matchable(),
                                Ref::keyword("IDENTITY").to_matchable(),
                                Bracketed::new(vec![
                                    AnyNumberOf::new(vec![
                                        Ref::new("AlterSequenceOptionsSegment").to_matchable(),
                                    ])
                                    .config(|this| this.optional())
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                one_of(vec![
                                    Sequence::new(vec![
                                        Ref::keyword("SET").to_matchable(),
                                        Ref::keyword("GENERATED").to_matchable(),
                                        one_of(vec![
                                            Ref::keyword("ALWAYS").to_matchable(),
                                            Sequence::new(vec![
                                                Ref::keyword("BY").to_matchable(),
                                                Ref::keyword("DEFAULT").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("SET").to_matchable(),
                                        Ref::new("AlterSequenceOptionsSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("RESTART").to_matchable(),
                                        Sequence::new(vec![
                                            Ref::keyword("WITH").to_matchable(),
                                            Ref::new("NumericLiteralSegment").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("DROP").to_matchable(),
                                Ref::keyword("IDENTITY").to_matchable(),
                                Ref::new("IfExistsGrammar").optional().to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("STATISTICS").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::new("RelationOptionsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("RESET").to_matchable(),
                                Ref::new("RelationOptionsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("STORAGE").to_matchable(),
                                one_of(vec![
                                    Ref::keyword("PLAIN").to_matchable(),
                                    Ref::keyword("EXTERNAL").to_matchable(),
                                    Ref::keyword("EXTENDED").to_matchable(),
                                    Ref::keyword("MAIN").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ADD").to_matchable(),
                        Ref::new("TableConstraintSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ADD").to_matchable(),
                        Ref::new("TableConstraintUsingIndexSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ALTER").to_matchable(),
                        Ref::keyword("CONSTRAINT").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                        one_of(vec![
                            Ref::keyword("DEFERRABLE").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("NOT").to_matchable(),
                                Ref::keyword("DEFERRABLE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("INITIALLY").to_matchable(),
                                Ref::keyword("DEFERRED").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("INITIALLY").to_matchable(),
                                Ref::keyword("IMMEDIATE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("VALIDATE").to_matchable(),
                        Ref::keyword("CONSTRAINT").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("DROP").to_matchable(),
                        Ref::keyword("CONSTRAINT").to_matchable(),
                        Ref::new("IfExistsGrammar").optional().to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                        Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("ENABLE").to_matchable(),
                            Ref::keyword("DISABLE").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("TRIGGER").to_matchable(),
                        one_of(vec![
                            Ref::new("ParameterNameSegment").to_matchable(),
                            Ref::keyword("ALL").to_matchable(),
                            Ref::keyword("USER").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ENABLE").to_matchable(),
                        one_of(vec![
                            Ref::keyword("REPLICA").to_matchable(),
                            Ref::keyword("ALWAYS").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("TRIGGER").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("ENABLE").to_matchable(),
                            Ref::keyword("DISABLE").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ENABLE").to_matchable(),
                                Ref::keyword("REPLICA").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ENABLE").to_matchable(),
                                Ref::keyword("RULE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("RULE").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("DISABLE").to_matchable(),
                            Ref::keyword("ENABLE").to_matchable(),
                            Ref::keyword("FORCE").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("NO").to_matchable(),
                                Ref::keyword("FORCE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("ROW").to_matchable(),
                        Ref::keyword("LEVEL").to_matchable(),
                        Ref::keyword("SECURITY").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("CLUSTER").to_matchable(),
                        Ref::keyword("ON").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("WITHOUT").to_matchable(),
                        one_of(vec![
                            Ref::keyword("CLUSTER").to_matchable(),
                            Ref::keyword("OIDS").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        one_of(vec![
                            Ref::keyword("LOGGED").to_matchable(),
                            Ref::keyword("UNLOGGED").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::new("RelationOptionsSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RESET").to_matchable(),
                        Ref::new("RelationOptionsSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NO").optional().to_matchable(),
                        Ref::keyword("INHERIT").to_matchable(),
                        Ref::new("TableReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OF").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NOT").to_matchable(),
                        Ref::keyword("OF").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OWNER").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        one_of(vec![
                            Ref::new("ParameterNameSegment").to_matchable(),
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("REPLICA").to_matchable(),
                        Ref::keyword("IDENTITY").to_matchable(),
                        one_of(vec![
                            Ref::keyword("DEFAULT").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("USING").to_matchable(),
                                Ref::keyword("INDEX").to_matchable(),
                                Ref::new("IndexReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("FULL").to_matchable(),
                            Ref::keyword("NOTHING").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "VersionIdentifierSegment".into(),
            NodeMatcher::new(SyntaxKind::VersionIdentifier, |_| {
                one_of(vec![
                    Ref::new("QuotedLiteralSegment").to_matchable(),
                    Ref::new("NakedIdentifierSegment").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateExtensionStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateExtensionStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("EXTENSION").to_matchable(),
                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                    Ref::new("ExtensionReferenceSegment").to_matchable(),
                    Ref::keyword("WITH").optional().to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SCHEMA").to_matchable(),
                        Ref::new("SchemaReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("VERSION").to_matchable(),
                        Ref::new("VersionIdentifierSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("FROM").to_matchable(),
                        Ref::new("VersionIdentifierSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DropExtensionStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropExtensionStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("EXTENSION").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Ref::new("ExtensionReferenceSegment").to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "PublicationReferenceSegment".into(),
            NodeMatcher::new(SyntaxKind::PublicationReference, |_| {
                Ref::new("SingleIdentifierGrammar").to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "PublicationTableSegment".into(),
            NodeMatcher::new(SyntaxKind::PublicationTable, |_| {
                Sequence::new(vec![
                    Ref::new("ExtendedTableReferenceGrammar").to_matchable(),
                    Ref::new("BracketedColumnReferenceListGrammar")
                        .optional()
                        .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WHERE").to_matchable(),
                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "PublicationObjectsSegment".into(),
            NodeMatcher::new(SyntaxKind::PublicationObjects, |_| {
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("TABLE").to_matchable(),
                        Delimited::new(vec![Ref::new("PublicationTableSegment").to_matchable()])
                            .config(|this| {
                                this.terminators = vec![
                                    Sequence::new(vec![
                                        Ref::new("CommaSegment").to_matchable(),
                                        one_of(vec![
                                            Ref::keyword("TABLE").to_matchable(),
                                            Ref::keyword("TABLES").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ];
                            })
                            .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("TABLES").to_matchable(),
                        Ref::keyword("IN").to_matchable(),
                        Ref::keyword("SCHEMA").to_matchable(),
                        Delimited::new(vec![
                            one_of(vec![
                                Ref::new("SchemaReferenceSegment").to_matchable(),
                                Ref::keyword("CURRENT_SCHEMA").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| {
                            this.terminators = vec![
                                Sequence::new(vec![
                                    Ref::new("CommaSegment").to_matchable(),
                                    one_of(vec![
                                        Ref::keyword("TABLE").to_matchable(),
                                        Ref::keyword("TABLES").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ];
                        })
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreatePublicationStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreatePublicationStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("PUBLICATION").to_matchable(),
                    Ref::new("PublicationReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("FOR").to_matchable(),
                            Ref::keyword("ALL").to_matchable(),
                            Ref::keyword("TABLES").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("FOR").to_matchable(),
                            Delimited::new(vec![
                                Ref::new("PublicationObjectsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("DefinitionParametersSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterPublicationStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterPublicationStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("PUBLICATION").to_matchable(),
                    Ref::new("PublicationReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::new("DefinitionParametersSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ADD").to_matchable(),
                            Delimited::new(vec![
                                Ref::new("PublicationObjectsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Delimited::new(vec![
                                Ref::new("PublicationObjectsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("DROP").to_matchable(),
                            Delimited::new(vec![
                                Ref::new("PublicationObjectsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("PublicationReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                                Ref::new("RoleReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.add([
        (
            "DropPublicationStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropPublicationStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("PUBLICATION").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Delimited::new(vec![Ref::new("PublicationReferenceSegment").to_matchable()])
                        .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateMaterializedViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
                    Ref::keyword("MATERIALIZED").to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("BracketedColumnReferenceListGrammar")
                        .optional()
                        .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USING").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("RelationOptionsSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    one_of(vec![
                        optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
                            .to_matchable(),
                        optionally_bracketed(vec![
                            Sequence::new(vec![
                                Ref::keyword("TABLE").to_matchable(),
                                Ref::new("TableReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::new("ValuesClauseSegment").to_matchable(),
                        optionally_bracketed(vec![
                            Sequence::new(vec![
                                Ref::keyword("EXECUTE").to_matchable(),
                                Ref::new("FunctionSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("WithDataClauseSegment").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterMaterializedViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterMaterializedViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("MATERIALIZED").to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::new("IfExistsGrammar").optional().to_matchable(),
                            Ref::new("TableReferenceSegment").to_matchable(),
                            one_of(vec![
                                Delimited::new(vec![
                                    Ref::new("AlterMaterializedViewActionSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("RENAME").to_matchable(),
                                    Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()])
                                        .config(|this| this.optional())
                                        .to_matchable(),
                                    Ref::new("ColumnReferenceSegment").to_matchable(),
                                    Ref::keyword("TO").to_matchable(),
                                    Ref::new("ColumnReferenceSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("RENAME").to_matchable(),
                                    Ref::keyword("TO").to_matchable(),
                                    Ref::new("TableReferenceSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("SET").to_matchable(),
                                    Ref::keyword("SCHEMA").to_matchable(),
                                    Ref::new("SchemaReferenceSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::new("TableReferenceSegment").to_matchable(),
                            Ref::keyword("NO").optional().to_matchable(),
                            Ref::keyword("DEPENDS").to_matchable(),
                            Ref::keyword("ON").to_matchable(),
                            Ref::keyword("EXTENSION").to_matchable(),
                            Ref::new("ExtensionReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ALL").to_matchable(),
                            Ref::keyword("IN").to_matchable(),
                            Ref::keyword("TABLESPACE").to_matchable(),
                            Ref::new("TablespaceReferenceSegment").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("OWNED").to_matchable(),
                                Ref::keyword("BY").to_matchable(),
                                Delimited::new(vec![
                                    Ref::new("ObjectReferenceSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("TABLESPACE").to_matchable(),
                            Ref::new("TablespaceReferenceSegment").to_matchable(),
                            Sequence::new(vec![Ref::keyword("NOWAIT").to_matchable()])
                                .config(|this| this.optional())
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterMaterializedViewActionSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterMaterializedViewActionSegment, |_| {
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("ALTER").to_matchable(),
                        Ref::keyword("COLUMN").optional().to_matchable(),
                        Ref::new("ColumnReferenceSegment").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("STATISTICS").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Bracketed::new(vec![
                                    Delimited::new(vec![
                                        Sequence::new(vec![
                                            Ref::new("ParameterNameSegment").to_matchable(),
                                            Ref::new("EqualsSegment").to_matchable(),
                                            Ref::new("LiteralGrammar").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("RESET").to_matchable(),
                                Bracketed::new(vec![
                                    Delimited::new(vec![
                                        Ref::new("ParameterNameSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("STORAGE").to_matchable(),
                                one_of(vec![
                                    Ref::keyword("PLAIN").to_matchable(),
                                    Ref::keyword("EXTERNAL").to_matchable(),
                                    Ref::keyword("EXTENDED").to_matchable(),
                                    Ref::keyword("MAIN").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("COMPRESSION").to_matchable(),
                                Ref::new("ParameterNameSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("CLUSTER").to_matchable(),
                        Ref::keyword("ON").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("WITHOUT").to_matchable(),
                        Ref::keyword("CLUSTER").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                Sequence::new(vec![
                                    Ref::new("ParameterNameSegment").to_matchable(),
                                    Sequence::new(vec![
                                        Ref::new("EqualsSegment").to_matchable(),
                                        Ref::new("LiteralGrammar").to_matchable(),
                                    ])
                                    .config(|this| this.optional())
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RESET").to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OWNER").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        one_of(vec![
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "RefreshMaterializedViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::RefreshMaterializedViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("REFRESH").to_matchable(),
                    Ref::keyword("MATERIALIZED").to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    Ref::keyword("CONCURRENTLY").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("WithDataClauseSegment").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DropMaterializedViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("MATERIALIZED").to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
                        .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "WithCheckOptionSegment".into(),
            NodeMatcher::new(SyntaxKind::WithCheckOption, |_| {
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    one_of(vec![
                        Ref::keyword("CASCADED").to_matchable(),
                        Ref::keyword("LOCAL").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("CHECK").to_matchable(),
                    Ref::keyword("OPTION").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterPolicyStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterPolicyStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("POLICY").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    Ref::keyword("ON").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("TO").to_matchable(),
                            Delimited::new(vec![
                                one_of(vec![
                                    Ref::new("RoleReferenceSegment").to_matchable(),
                                    Ref::keyword("PUBLIC").to_matchable(),
                                    Ref::keyword("CURRENT_ROLE").to_matchable(),
                                    Ref::keyword("CURRENT_USER").to_matchable(),
                                    Ref::keyword("SESSION_USER").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("USING").to_matchable(),
                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("WITH").to_matchable(),
                            Ref::keyword("CHECK").to_matchable(),
                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.add([
        (
            "CreateViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
                    Ref::new("TemporaryGrammar").optional().to_matchable(),
                    Ref::keyword("RECURSIVE").optional().to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("BracketedColumnReferenceListGrammar")
                        .optional()
                        .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("RelationOptionsSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    one_of(vec![
                        optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
                            .to_matchable(),
                        Ref::new("ValuesClauseSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("WithCheckOptionSegment").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("ALTER").to_matchable(),
                            Ref::keyword("COLUMN").optional().to_matchable(),
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    Ref::keyword("SET").to_matchable(),
                                    Ref::keyword("DEFAULT").to_matchable(),
                                    one_of(vec![
                                        Ref::new("LiteralGrammar").to_matchable(),
                                        Ref::new("FunctionSegment").to_matchable(),
                                        Ref::new("BareFunctionSegment").to_matchable(),
                                        Ref::new("ExpressionSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("DROP").to_matchable(),
                                    Ref::keyword("DEFAULT").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("COLUMN").optional().to_matchable(),
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("TableReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("SchemaReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Bracketed::new(vec![
                                Delimited::new(vec![
                                    Sequence::new(vec![
                                        Ref::new("ParameterNameSegment").to_matchable(),
                                        Sequence::new(vec![
                                            Ref::new("EqualsSegment").to_matchable(),
                                            Ref::new("LiteralGrammar").to_matchable(),
                                        ])
                                        .config(|this| this.optional())
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RESET").to_matchable(),
                            Bracketed::new(vec![
                                Delimited::new(vec![
                                    Ref::new("ParameterNameSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.add([
        (
            "DropViewStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropViewStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("VIEW").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
                        .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateDatabaseStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("DATABASE").to_matchable(),
                    Ref::new("DatabaseReferenceSegment").to_matchable(),
                    Ref::keyword("WITH").optional().to_matchable(),
                    AnyNumberOf::new(vec![
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("TEMPLATE").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ENCODING").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            one_of(vec![
                                Ref::new("QuotedLiteralSegment").to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("LOCALE").to_matchable(),
                                Ref::new("EqualsSegment").optional().to_matchable(),
                                Ref::new("QuotedLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            AnyNumberOf::new(vec![
                                Sequence::new(vec![
                                    Ref::keyword("LC_COLLATE").to_matchable(),
                                    Ref::new("EqualsSegment").optional().to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("LC_CTYPE").to_matchable(),
                                    Ref::new("EqualsSegment").optional().to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("TABLESPACE").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            one_of(vec![
                                Ref::new("TablespaceReferenceSegment").to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ALLOW_CONNECTIONS").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            Ref::new("BooleanLiteralGrammar").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("CONNECTION").to_matchable(),
                            Ref::keyword("LIMIT").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            Ref::new("NumericLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("IS_TEMPLATE").to_matchable(),
                            Ref::new("EqualsSegment").optional().to_matchable(),
                            Ref::new("BooleanLiteralGrammar").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.add([(
        "AlterDatabaseStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_| {
            Sequence::new(vec![
                Ref::keyword("ALTER").to_matchable(),
                Ref::keyword("DATABASE").to_matchable(),
                Ref::new("DatabaseReferenceSegment").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("WITH").optional().to_matchable(),
                        AnyNumberOf::new(vec![
                            Sequence::new(vec![
                                Ref::keyword("ALLOW_CONNECTIONS").to_matchable(),
                                Ref::new("BooleanLiteralGrammar").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("CONNECTION").to_matchable(),
                                Ref::keyword("LIMIT").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("IS_TEMPLATE").to_matchable(),
                                Ref::new("BooleanLiteralGrammar").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.min_times(1))
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RENAME").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        Ref::new("DatabaseReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OWNER").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        one_of(vec![
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                one_of(vec![
                                    Ref::keyword("TO").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                one_of(vec![
                                    Ref::keyword("DEFAULT").to_matchable(),
                                    Ref::new("LiteralGrammar").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("FROM").to_matchable(),
                                Ref::keyword("CURRENT").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RESET").to_matchable(),
                        one_of(vec![
                            Ref::keyword("ALL").to_matchable(),
                            Ref::new("ParameterNameSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "DropDatabaseStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DROP").to_matchable(),
            Ref::keyword("DATABASE").to_matchable(),
            Ref::new("IfExistsGrammar").optional().to_matchable(),
            Ref::new("DatabaseReferenceSegment").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("WITH").optional().to_matchable(),
                Bracketed::new(vec![Ref::keyword("FORCE").to_matchable()]).to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "VacuumStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::VacuumStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("VACUUM").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("FULL").optional().to_matchable(),
                            Ref::keyword("FREEZE").optional().to_matchable(),
                            Ref::keyword("VERBOSE").optional().to_matchable(),
                            one_of(vec![
                                Ref::keyword("ANALYZE").to_matchable(),
                                Ref::keyword("ANALYSE").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                Sequence::new(vec![
                                    one_of(vec![
                                        Ref::keyword("FULL").to_matchable(),
                                        Ref::keyword("FREEZE").to_matchable(),
                                        Ref::keyword("VERBOSE").to_matchable(),
                                        Ref::keyword("ANALYZE").to_matchable(),
                                        Ref::keyword("ANALYSE").to_matchable(),
                                        Ref::keyword("DISABLE_PAGE_SKIPPING").to_matchable(),
                                        Ref::keyword("SKIP_LOCKED").to_matchable(),
                                        Ref::keyword("INDEX_CLEANUP").to_matchable(),
                                        Ref::keyword("PROCESS_TOAST").to_matchable(),
                                        Ref::keyword("TRUNCATE").to_matchable(),
                                        Ref::keyword("PARALLEL").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    one_of(vec![
                                        Ref::new("LiteralGrammar").to_matchable(),
                                        Ref::new("NakedIdentifierSegment").to_matchable(),
                                        Ref::new("OnKeywordAsIdentifierSegment").to_matchable(),
                                    ])
                                    .config(|this| this.optional())
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("TableReferenceSegment").to_matchable(),
                            Ref::new("BracketedColumnReferenceListGrammar")
                                .optional()
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "LikeOptionSegment".into(),
            NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_| {
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("INCLUDING").to_matchable(),
                        Ref::keyword("EXCLUDING").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("COMMENTS").to_matchable(),
                        Ref::keyword("CONSTRAINTS").to_matchable(),
                        Ref::keyword("DEFAULTS").to_matchable(),
                        Ref::keyword("GENERATED").to_matchable(),
                        Ref::keyword("IDENTITY").to_matchable(),
                        Ref::keyword("INDEXES").to_matchable(),
                        Ref::keyword("STATISTICS").to_matchable(),
                        Ref::keyword("STORAGE").to_matchable(),
                        Ref::keyword("ALL").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "ColumnConstraintSegment",
        Sequence::new(vec![
            Sequence::new(vec![
                Ref::keyword("CONSTRAINT").to_matchable(),
                Ref::new("ObjectReferenceSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("NOT").optional().to_matchable(),
                    Ref::keyword("NULL").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("CHECK").to_matchable(),
                    Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                        .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NO").to_matchable(),
                        Ref::keyword("INHERIT").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("DEFAULT").to_matchable(),
                    one_of(vec![
                        Ref::new("ShorthandCastSegment").to_matchable(),
                        Ref::new("LiteralGrammar").to_matchable(),
                        Ref::new("FunctionSegment").to_matchable(),
                        Ref::new("BareFunctionSegment").to_matchable(),
                        Ref::new("ExpressionSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("GENERATED").to_matchable(),
                    Ref::keyword("ALWAYS").to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    Ref::new("ExpressionSegment").to_matchable(),
                    Ref::keyword("STORED").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("GENERATED").to_matchable(),
                    one_of(vec![
                        Ref::keyword("ALWAYS").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("BY").to_matchable(),
                            Ref::keyword("DEFAULT").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    Ref::keyword("IDENTITY").to_matchable(),
                    Bracketed::new(vec![
                        AnyNumberOf::new(vec![
                            Ref::new("AlterSequenceOptionsSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("UNIQUE").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NULLS").to_matchable(),
                        Ref::keyword("NOT").optional().to_matchable(),
                        Ref::keyword("DISTINCT").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("DefinitionParametersSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USING").to_matchable(),
                        Ref::keyword("INDEX").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("PRIMARY").to_matchable(),
                    Ref::keyword("KEY").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("DefinitionParametersSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USING").to_matchable(),
                        Ref::keyword("INDEX").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Ref::new("ReferenceDefinitionGrammar").to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Ref::keyword("DEFERRABLE").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NOT").to_matchable(),
                    Ref::keyword("DEFERRABLE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("INITIALLY").to_matchable(),
                    Ref::keyword("DEFERRED").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("INITIALLY").to_matchable(),
                    Ref::keyword("IMMEDIATE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "PartitionBoundSpecSegment".into(),
        NodeMatcher::new(SyntaxKind::PartitionBoundSpec, |_| {
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("IN").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("FROM").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            one_of(vec![
                                Ref::new("ExpressionSegment").to_matchable(),
                                Ref::keyword("MINVALUE").to_matchable(),
                                Ref::keyword("MAXVALUE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            one_of(vec![
                                Ref::new("ExpressionSegment").to_matchable(),
                                Ref::keyword("MINVALUE").to_matchable(),
                                Ref::keyword("MAXVALUE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Bracketed::new(vec![
                        Sequence::new(vec![
                            Ref::keyword("MODULUS").to_matchable(),
                            Ref::new("NumericLiteralSegment").to_matchable(),
                            Ref::new("CommaSegment").to_matchable(),
                            Ref::keyword("REMAINDER").to_matchable(),
                            Ref::new("NumericLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([(
        "TableConstraintSegment".into(),
        NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
            Sequence::new(vec![
                Sequence::new(vec![
                    Ref::keyword("CONSTRAINT").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("CHECK").to_matchable(),
                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NO").to_matchable(),
                            Ref::keyword("INHERIT").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("UNIQUE").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NULLS").to_matchable(),
                            Ref::keyword("NOT").optional().to_matchable(),
                            Ref::keyword("DISTINCT").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
                        Ref::new("IndexParametersSegment").optional().to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::new("PrimaryKeyGrammar").to_matchable(),
                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
                        Ref::new("IndexParametersSegment").optional().to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("EXCLUDE").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("USING").to_matchable(),
                            Ref::new("IndexAccessMethodSegment").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                Ref::new("ExclusionConstraintElementSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::new("IndexParametersSegment").optional().to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("WHERE").to_matchable(),
                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("FOREIGN").to_matchable(),
                        Ref::keyword("KEY").to_matchable(),
                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
                        Ref::new("ReferenceDefinitionGrammar").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                AnyNumberOf::new(vec![
                    one_of(vec![
                        Ref::keyword("DEFERRABLE").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("NOT").to_matchable(),
                            Ref::keyword("DEFERRABLE").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("INITIALLY").to_matchable(),
                            Ref::keyword("DEFERRED").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("INITIALLY").to_matchable(),
                            Ref::keyword("IMMEDIATE").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NOT").to_matchable(),
                        Ref::keyword("VALID").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NO").to_matchable(),
                        Ref::keyword("INHERIT").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([(
        "TableConstraintUsingIndexSegment".into(),
        NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
            Sequence::new(vec![
                Sequence::new(vec![
                    Ref::keyword("CONSTRAINT").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("UNIQUE").to_matchable(),
                        Ref::new("PrimaryKeyGrammar").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("USING").to_matchable(),
                    Ref::keyword("INDEX").to_matchable(),
                    Ref::new("IndexReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
                one_of(vec![
                    Ref::keyword("DEFERRABLE").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NOT").to_matchable(),
                        Ref::keyword("DEFERRABLE").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("INITIALLY").to_matchable(),
                        Ref::keyword("DEFERRED").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("INITIALLY").to_matchable(),
                        Ref::keyword("IMMEDIATE").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([
        (
            "IndexParametersSegment".into(),
            NodeMatcher::new(SyntaxKind::IndexParameters, |_| {
                Sequence::new(vec![
                    Sequence::new(vec![
                        Ref::keyword("INCLUDE").to_matchable(),
                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::new("DefinitionParametersSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USING").to_matchable(),
                        Ref::keyword("INDEX").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ReferentialActionSegment".into(),
            NodeMatcher::new(SyntaxKind::ReferentialActionSegment, |_| {
                one_of(vec![
                    Ref::keyword("CASCADE").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("NULL").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("DEFAULT").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("RESTRICT").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NO").to_matchable(),
                        Ref::keyword("ACTION").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "IndexElementOptionsSegment".into(),
            NodeMatcher::new(SyntaxKind::IndexElementOptions, |_| {
                Sequence::new(vec![
                    Sequence::new(vec![
                        Ref::keyword("COLLATE").to_matchable(),
                        Ref::new("CollationReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::new("OperatorClassReferenceSegment")
                            .config(|this| {
                                this.exclude = Some(
                                    Sequence::new(vec![
                                        Ref::keyword("NULLS").to_matchable(),
                                        one_of(vec![
                                            Ref::keyword("FIRST").to_matchable(),
                                            Ref::keyword("LAST").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                );
                            })
                            .to_matchable(),
                        Ref::new("RelationOptionsSegment").optional().to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    one_of(vec![
                        Ref::keyword("ASC").to_matchable(),
                        Ref::keyword("DESC").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NULLS").to_matchable(),
                        one_of(vec![
                            Ref::keyword("FIRST").to_matchable(),
                            Ref::keyword("LAST").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "IndexElementSegment".into(),
            NodeMatcher::new(SyntaxKind::IndexElement, |_| {
                Sequence::new(vec![
                    one_of(vec![
                        Ref::new("ColumnReferenceSegment").to_matchable(),
                        Ref::new("FunctionSegment").to_matchable(),
                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("IndexElementOptionsSegment")
                        .optional()
                        .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ExclusionConstraintElementSegment".into(),
            NodeMatcher::new(SyntaxKind::ExclusionConstraintElement, |_| {
                Sequence::new(vec![
                    Ref::new("IndexElementSegment").to_matchable(),
                    Ref::keyword("WITH").to_matchable(),
                    Ref::new("ComparisonOperatorGrammar").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDefaultPrivilegesStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("DEFAULT").to_matchable(),
                    Ref::keyword("PRIVILEGES").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("FOR").to_matchable(),
                        one_of(vec![
                            Ref::keyword("ROLE").to_matchable(),
                            Ref::keyword("USER").to_matchable(),
                        ])
                        .to_matchable(),
                        Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
                            .config(|this| {
                                this.terminators = vec![
                                    Ref::keyword("IN").to_matchable(),
                                    Ref::keyword("GRANT").to_matchable(),
                                    Ref::keyword("REVOKE").to_matchable(),
                                ];
                            })
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("IN").to_matchable(),
                        Ref::keyword("SCHEMA").to_matchable(),
                        Delimited::new(vec![Ref::new("SchemaReferenceSegment").to_matchable()])
                            .config(|this| {
                                this.terminators = vec![
                                    Ref::keyword("GRANT").to_matchable(),
                                    Ref::keyword("REVOKE").to_matchable(),
                                ];
                            })
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    one_of(vec![
                        Ref::new("AlterDefaultPrivilegesGrantSegment").to_matchable(),
                        Ref::new("AlterDefaultPrivilegesRevokeSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDefaultPrivilegesObjectPrivilegesSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesObjectPrivilege, |_| {
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("ALL").to_matchable(),
                        Ref::keyword("PRIVILEGES").optional().to_matchable(),
                    ])
                    .to_matchable(),
                    Delimited::new(vec![
                        Ref::keyword("CREATE").to_matchable(),
                        Ref::keyword("DELETE").to_matchable(),
                        Ref::keyword("EXECUTE").to_matchable(),
                        Ref::keyword("INSERT").to_matchable(),
                        Ref::keyword("REFERENCES").to_matchable(),
                        Ref::keyword("SELECT").to_matchable(),
                        Ref::keyword("TRIGGER").to_matchable(),
                        Ref::keyword("TRUNCATE").to_matchable(),
                        Ref::keyword("UPDATE").to_matchable(),
                        Ref::keyword("USAGE").to_matchable(),
                    ])
                    .config(|this| {
                        this.terminators = vec![Ref::keyword("ON").to_matchable()];
                    })
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDefaultPrivilegesSchemaObjectsSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesSchemaObject, |_| {
                one_of(vec![
                    Ref::keyword("TABLES").to_matchable(),
                    Ref::keyword("FUNCTIONS").to_matchable(),
                    Ref::keyword("ROUTINES").to_matchable(),
                    Ref::keyword("SEQUENCES").to_matchable(),
                    Ref::keyword("TYPES").to_matchable(),
                    Ref::keyword("SCHEMAS").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDefaultPrivilegesToFromRolesSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesToFromRoles, |_| {
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("GROUP").optional().to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("PUBLIC").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDefaultPrivilegesGrantSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesGrant, |_| {
                Sequence::new(vec![
                    Ref::keyword("GRANT").to_matchable(),
                    Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(),
                    Ref::keyword("ON").to_matchable(),
                    Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    Delimited::new(vec![
                        Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(),
                    ])
                    .config(|this| {
                        this.terminators = vec![Ref::keyword("WITH").to_matchable()];
                    })
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::keyword("GRANT").to_matchable(),
                        Ref::keyword("OPTION").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDefaultPrivilegesRevokeSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesRevoke, |_| {
                Sequence::new(vec![
                    Ref::keyword("REVOKE").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("GRANT").to_matchable(),
                        Ref::keyword("OPTION").to_matchable(),
                        Ref::keyword("FOR").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(),
                    Ref::keyword("ON").to_matchable(),
                    Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(),
                    Ref::keyword("FROM").to_matchable(),
                    Delimited::new(vec![
                        Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(),
                    ])
                    .config(|this| {
                        this.terminators = vec![
                            Ref::keyword("RESTRICT").to_matchable(),
                            Ref::keyword("CASCADE").to_matchable(),
                        ];
                    })
                    .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DropOwnedStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropOwnedStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("OWNED").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                    Delimited::new(vec![
                        one_of(vec![
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                            Ref::new("RoleReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ReassignOwnedStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::ReassignOwnedStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("REASSIGN").to_matchable(),
                    Ref::keyword("OWNED").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                    Delimited::new(vec![
                        one_of(vec![
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                            Ref::new("RoleReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    one_of(vec![
                        Ref::keyword("CURRENT_ROLE").to_matchable(),
                        Ref::keyword("CURRENT_USER").to_matchable(),
                        Ref::keyword("SESSION_USER").to_matchable(),
                        Ref::new("RoleReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CommentOnStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CommentClause, |_| {
                Sequence::new(vec![
                    Ref::keyword("COMMENT").to_matchable(),
                    Ref::keyword("ON").to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Sequence::new(vec![
                                one_of(vec![
                                    Ref::keyword("TABLE").to_matchable(),
                                    Ref::keyword("VIEW").to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::new("TableReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("CAST").to_matchable(),
                                Bracketed::new(vec![
                                    Sequence::new(vec![
                                        Ref::new("ObjectReferenceSegment").to_matchable(),
                                        Ref::keyword("AS").to_matchable(),
                                        Ref::new("ObjectReferenceSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("COLUMN").to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("CONSTRAINT").to_matchable(),
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("ON").to_matchable(),
                                    Ref::keyword("DOMAIN").optional().to_matchable(),
                                    Ref::new("ObjectReferenceSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("DATABASE").to_matchable(),
                                Ref::new("DatabaseReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("EXTENSION").to_matchable(),
                                Ref::new("ExtensionReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("FUNCTION").to_matchable(),
                                Ref::new("FunctionNameSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::new("FunctionParameterListGrammar").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("INDEX").to_matchable(),
                                Ref::new("IndexReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SCHEMA").to_matchable(),
                                Ref::new("SchemaReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                one_of(vec![
                                    Ref::keyword("COLLATION").to_matchable(),
                                    Ref::keyword("CONVERSION").to_matchable(),
                                    Ref::keyword("DOMAIN").to_matchable(),
                                    Ref::keyword("LANGUAGE").to_matchable(),
                                    Ref::keyword("POLICY").to_matchable(),
                                    Ref::keyword("PUBLICATION").to_matchable(),
                                    Ref::keyword("ROLE").to_matchable(),
                                    Ref::keyword("RULE").to_matchable(),
                                    Ref::keyword("SEQUENCE").to_matchable(),
                                    Ref::keyword("SERVER").to_matchable(),
                                    Ref::keyword("STATISTICS").to_matchable(),
                                    Ref::keyword("SUBSCRIPTION").to_matchable(),
                                    Ref::keyword("TABLESPACE").to_matchable(),
                                    Ref::keyword("TRIGGER").to_matchable(),
                                    Ref::keyword("TYPE").to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("ACCESS").to_matchable(),
                                        Ref::keyword("METHOD").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("EVENT").to_matchable(),
                                        Ref::keyword("TRIGGER").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("FOREIGN").to_matchable(),
                                        Ref::keyword("DATA").to_matchable(),
                                        Ref::keyword("WRAPPER").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("FOREIGN").to_matchable(),
                                        Ref::keyword("TABLE").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("MATERIALIZED").to_matchable(),
                                        Ref::keyword("VIEW").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("TEXT").to_matchable(),
                                        Ref::keyword("SEARCH").to_matchable(),
                                        Ref::keyword("CONFIGURATION").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("TEXT").to_matchable(),
                                        Ref::keyword("SEARCH").to_matchable(),
                                        Ref::keyword("DICTIONARY").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("TEXT").to_matchable(),
                                        Ref::keyword("SEARCH").to_matchable(),
                                        Ref::keyword("PARSER").to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("TEXT").to_matchable(),
                                        Ref::keyword("SEARCH").to_matchable(),
                                        Ref::keyword("TEMPLATE").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("ON").to_matchable(),
                                    Ref::new("ObjectReferenceSegment").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                one_of(vec![
                                    Ref::keyword("AGGREGATE").to_matchable(),
                                    Ref::keyword("PROCEDURE").to_matchable(),
                                    Ref::keyword("ROUTINE").to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                                Bracketed::new(vec![
                                    Sequence::new(vec![Anything::new().to_matchable()])
                                        .config(|this| this.optional())
                                        .to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("IS").to_matchable(),
                            one_of(vec![
                                Ref::new("QuotedLiteralSegment").to_matchable(),
                                Ref::keyword("NULL").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "CreateIndexStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            Ref::keyword("UNIQUE").optional().to_matchable(),
            Ref::keyword("INDEX").to_matchable(),
            Ref::keyword("CONCURRENTLY").optional().to_matchable(),
            Sequence::new(vec![
                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                Ref::new("IndexReferenceSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Ref::keyword("ON").to_matchable(),
            Ref::keyword("ONLY").optional().to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("USING").to_matchable(),
                Ref::new("IndexAccessMethodSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Bracketed::new(vec![
                Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()]).to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("INCLUDE").to_matchable(),
                Bracketed::new(vec![
                    Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("NULLS").to_matchable(),
                Ref::keyword("NOT").optional().to_matchable(),
                Ref::keyword("DISTINCT").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("WITH").to_matchable(),
                Ref::new("RelationOptionsSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("TABLESPACE").to_matchable(),
                Ref::new("TablespaceReferenceSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("WHERE").to_matchable(),
                Ref::new("ExpressionSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "AlterIndexStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::AlterIndexStatement, |_| {
            Sequence::new(vec![
                Ref::keyword("ALTER").to_matchable(),
                Ref::keyword("INDEX").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::new("IfExistsGrammar").optional().to_matchable(),
                        Ref::new("IndexReferenceSegment").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("RENAME").to_matchable(),
                                Ref::keyword("TO").to_matchable(),
                                Ref::new("IndexReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("TABLESPACE").to_matchable(),
                                Ref::new("TablespaceReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ATTACH").to_matchable(),
                                Ref::keyword("PARTITION").to_matchable(),
                                Ref::new("IndexReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("NO").optional().to_matchable(),
                                Ref::keyword("DEPENDS").to_matchable(),
                                Ref::keyword("ON").to_matchable(),
                                Ref::keyword("EXTENSION").to_matchable(),
                                Ref::new("ExtensionReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SET").to_matchable(),
                                Bracketed::new(vec![
                                    Delimited::new(vec![
                                        Sequence::new(vec![
                                            Ref::new("ParameterNameSegment").to_matchable(),
                                            Sequence::new(vec![
                                                Ref::new("EqualsSegment").to_matchable(),
                                                Ref::new("LiteralGrammar").to_matchable(),
                                            ])
                                            .config(|this| this.optional())
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("RESET").to_matchable(),
                                Bracketed::new(vec![
                                    Delimited::new(vec![
                                        Ref::new("ParameterNameSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ALTER").to_matchable(),
                                Ref::keyword("COLUMN").optional().to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("STATISTICS").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ALL").to_matchable(),
                        Ref::keyword("IN").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNED").to_matchable(),
                            Ref::keyword("BY").to_matchable(),
                            Delimited::new(vec![Ref::new("RoleReferenceSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                        Ref::keyword("SET").to_matchable(),
                        Ref::keyword("TABLESPACE").to_matchable(),
                        Ref::new("TablespaceReferenceSegment").to_matchable(),
                        Ref::keyword("NOWAIT").optional().to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([(
        "ReindexStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::ReindexStatementSegment, |_| {
            Sequence::new(vec![
                Ref::keyword("REINDEX").to_matchable(),
                Bracketed::new(vec![
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::keyword("CONCURRENTLY").to_matchable(),
                            Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("TABLESPACE").to_matchable(),
                            Ref::new("TablespaceReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("VERBOSE").to_matchable(),
                            Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("INDEX").to_matchable(),
                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
                        Ref::new("IndexReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("TABLE").to_matchable(),
                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
                        Ref::new("TableReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SCHEMA").to_matchable(),
                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
                        Ref::new("SchemaReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("DATABASE").to_matchable(),
                            Ref::keyword("SYSTEM").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
                        Ref::new("DatabaseReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "DropIndexStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DROP").to_matchable(),
            Ref::keyword("INDEX").to_matchable(),
            Ref::keyword("CONCURRENTLY").optional().to_matchable(),
            Ref::new("IfExistsGrammar").optional().to_matchable(),
            Delimited::new(vec![Ref::new("IndexReferenceSegment").to_matchable()]).to_matchable(),
            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "FrameClauseSegment",
        {
            let frame_extent = ansi::frame_extent();

            let frame_exclusion = Sequence::new(vec![
                Ref::keyword("EXCLUDE").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("CURRENT").to_matchable(),
                        Ref::keyword("ROW").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("GROUP").to_matchable(),
                    Ref::keyword("TIES").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NO").to_matchable(),
                        Ref::keyword("OTHERS").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional());

            Sequence::new(vec![
                Ref::new("FrameClauseUnitGrammar").to_matchable(),
                one_of(vec![
                    frame_extent.clone().to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("BETWEEN").to_matchable(),
                        frame_extent.clone().to_matchable(),
                        Ref::keyword("AND").to_matchable(),
                        frame_extent.clone().to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                frame_exclusion.to_matchable(),
            ])
        }
        .to_matchable(),
    );

    postgres.replace_grammar(
        "CreateSequenceOptionsSegment",
        one_of(vec![
            Sequence::new(vec![
                Ref::keyword("AS").to_matchable(),
                Ref::new("DatatypeSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("INCREMENT").to_matchable(),
                Ref::keyword("BY").optional().to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("MINVALUE").to_matchable(),
                    Ref::new("NumericLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NO").to_matchable(),
                    Ref::keyword("MINVALUE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("MAXVALUE").to_matchable(),
                    Ref::new("NumericLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NO").to_matchable(),
                    Ref::keyword("MAXVALUE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("START").to_matchable(),
                Ref::keyword("WITH").optional().to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("CACHE").to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Ref::keyword("CYCLE").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NO").to_matchable(),
                    Ref::keyword("CYCLE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("OWNED").to_matchable(),
                Ref::keyword("BY").to_matchable(),
                one_of(vec![
                    Ref::keyword("NONE").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "CreateSequenceStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_| {
            Sequence::new(vec![
                Ref::keyword("CREATE").to_matchable(),
                Ref::new("TemporaryGrammar").optional().to_matchable(),
                Ref::keyword("SEQUENCE").to_matchable(),
                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                Ref::new("SequenceReferenceSegment").to_matchable(),
                AnyNumberOf::new(vec![
                    Ref::new("CreateSequenceOptionsSegment").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "AlterSequenceOptionsSegment",
        one_of(vec![
            Sequence::new(vec![
                Ref::keyword("AS").to_matchable(),
                Ref::new("DatatypeSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("INCREMENT").to_matchable(),
                Ref::keyword("BY").optional().to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("MINVALUE").to_matchable(),
                    Ref::new("NumericLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NO").to_matchable(),
                    Ref::keyword("MINVALUE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("MAXVALUE").to_matchable(),
                    Ref::new("NumericLiteralSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("NO").to_matchable(),
                    Ref::keyword("MAXVALUE").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("SEQUENCE").to_matchable(),
                Ref::keyword("NAME").to_matchable(),
                Ref::new("SequenceReferenceSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("START").to_matchable(),
                Ref::keyword("WITH").optional().to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("RESTART").to_matchable(),
                Ref::keyword("WITH").optional().to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("CACHE").to_matchable(),
                Ref::new("NumericLiteralSegment").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("NO").optional().to_matchable(),
                Ref::keyword("CYCLE").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("OWNED").to_matchable(),
                Ref::keyword("BY").to_matchable(),
                one_of(vec![
                    Ref::keyword("NONE").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "AlterSequenceStatementSegment",
        Sequence::new(vec![
            Ref::keyword("ALTER").to_matchable(),
            Ref::keyword("SEQUENCE").to_matchable(),
            Ref::new("IfExistsGrammar").optional().to_matchable(),
            Ref::new("SequenceReferenceSegment").to_matchable(),
            one_of(vec![
                AnyNumberOf::new(vec![Ref::new("AlterSequenceOptionsSegment").to_matchable()])
                    .config(|this| this.optional())
                    .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("OWNER").to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    one_of(vec![
                        Ref::new("ParameterNameSegment").to_matchable(),
                        Ref::keyword("CURRENT_USER").to_matchable(),
                        Ref::keyword("SESSION_USER").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("RENAME").to_matchable(),
                    Ref::keyword("TO").to_matchable(),
                    Ref::new("SequenceReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("SET").to_matchable(),
                    Ref::keyword("SCHEMA").to_matchable(),
                    Ref::new("SchemaReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "DropSequenceStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DROP").to_matchable(),
            Ref::keyword("SEQUENCE").to_matchable(),
            Ref::new("IfExistsGrammar").optional().to_matchable(),
            Delimited::new(vec![Ref::new("SequenceReferenceSegment").to_matchable()])
                .to_matchable(),
            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "AnalyzeStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::AnalyzeStatement, |_| {
            {
                let option = Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("VERBOSE").to_matchable(),
                        Ref::keyword("SKIP_LOCKED").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
                ]);

                let tables_and_columns = Sequence::new(vec![
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ]);

                Sequence::new(vec![
                    one_of(vec![
                        Ref::keyword("ANALYZE").to_matchable(),
                        Ref::keyword("ANALYSE").to_matchable(),
                    ])
                    .to_matchable(),
                    one_of(vec![
                        Bracketed::new(vec![
                            Delimited::new(vec![option.to_matchable()]).to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("VERBOSE").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Delimited::new(vec![tables_and_columns.to_matchable()])
                        .config(|this| this.optional())
                        .to_matchable(),
                ])
            }
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar("StatementSegment", statement_segment());

    postgres.replace_grammar(
        "CreateTriggerStatementSegment",
        Sequence::new(vec![
            Ref::keyword("CREATE").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("OR").to_matchable(),
                Ref::keyword("REPLACE").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Ref::keyword("CONSTRAINT").optional().to_matchable(),
            Ref::keyword("TRIGGER").to_matchable(),
            Ref::new("TriggerReferenceSegment").to_matchable(),
            one_of(vec![
                Ref::keyword("BEFORE").to_matchable(),
                Ref::keyword("AFTER").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("INSTEAD").to_matchable(),
                    Ref::keyword("OF").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Delimited::new(vec![
                Ref::keyword("INSERT").to_matchable(),
                Ref::keyword("DELETE").to_matchable(),
                Ref::keyword("TRUNCATE").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("UPDATE").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("OF").to_matchable(),
                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
                            .config(|this| {
                                this.terminators = vec![
                                    Ref::keyword("OR").to_matchable(),
                                    Ref::keyword("ON").to_matchable(),
                                ];
                                this.optional();
                            })
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.delimiter(Ref::keyword("OR")))
            .to_matchable(),
            Ref::keyword("ON").to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            AnyNumberOf::new(vec![
                Sequence::new(vec![
                    Ref::keyword("FROM").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("NOT").to_matchable(),
                        Ref::keyword("DEFERRABLE").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("DEFERRABLE").optional().to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("INITIALLY").to_matchable(),
                                Ref::keyword("IMMEDIATE").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("INITIALLY").to_matchable(),
                                Ref::keyword("DEFERRED").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("REFERENCING").to_matchable(),
                    one_of(vec![
                        Ref::keyword("OLD").to_matchable(),
                        Ref::keyword("NEW").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("TABLE").to_matchable(),
                    Ref::keyword("AS").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Ref::keyword("OLD").to_matchable(),
                            Ref::keyword("NEW").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("TABLE").to_matchable(),
                        Ref::keyword("AS").to_matchable(),
                        Ref::new("TableReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("FOR").to_matchable(),
                    Ref::keyword("EACH").optional().to_matchable(),
                    one_of(vec![
                        Ref::keyword("ROW").to_matchable(),
                        Ref::keyword("STATEMENT").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WHEN").to_matchable(),
                    Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                        .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("EXECUTE").to_matchable(),
                one_of(vec![
                    Ref::keyword("FUNCTION").to_matchable(),
                    Ref::keyword("PROCEDURE").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("FunctionSegment").to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "AlterTriggerStatementSegment".into(),
        NodeMatcher::new(SyntaxKind::AlterTrigger, |_| {
            Sequence::new(vec![
                Ref::keyword("ALTER").to_matchable(),
                Ref::keyword("TRIGGER").to_matchable(),
                Ref::new("TriggerReferenceSegment").to_matchable(),
                Ref::keyword("ON").to_matchable(),
                Ref::new("TableReferenceSegment").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("RENAME").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        Ref::new("TriggerReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("NO").optional().to_matchable(),
                        Ref::keyword("DEPENDS").to_matchable(),
                        Ref::keyword("ON").to_matchable(),
                        Ref::keyword("EXTENSION").to_matchable(),
                        Ref::new("ExtensionReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "DropTriggerStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DROP").to_matchable(),
            Ref::keyword("TRIGGER").to_matchable(),
            Ref::new("IfExistsGrammar").optional().to_matchable(),
            Ref::new("TriggerReferenceSegment").to_matchable(),
            Ref::keyword("ON").to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "AliasExpressionSegment",
        Sequence::new(vec![
            Ref::keyword("AS").optional().to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::new("SingleIdentifierGrammar").to_matchable(),
                    Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()])
                        .config(|this| this.optional())
                        .to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::new("SingleIdentifierGrammar")
                        .optional()
                        .to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            Sequence::new(vec![
                                Ref::new("ParameterNameSegment").to_matchable(),
                                Ref::new("DatatypeSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "AsAliasExpressionSegment".into(),
        NodeMatcher::new(SyntaxKind::AliasExpression, |_| {
            Sequence::new(vec![
                MetaSegment::indent().to_matchable(),
                Ref::keyword("AS").to_matchable(),
                Ref::new("SingleIdentifierGrammar").to_matchable(),
                MetaSegment::dedent().to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([(
        "OperationClassReferenceSegment".into(),
        NodeMatcher::new(SyntaxKind::OperationClassReference, |postgres| {
            postgres
                .grammar("ObjectReferenceSegment")
                .match_grammar(postgres)
                .unwrap()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([
        (
            "ConflictActionSegment".into(),
            NodeMatcher::new(SyntaxKind::ConflictAction, |_| {
                Sequence::new(vec![
                    Ref::keyword("DO").to_matchable(),
                    one_of(vec![
                        Ref::keyword("NOTHING").to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("UPDATE").to_matchable(),
                            Ref::keyword("SET").to_matchable(),
                            Delimited::new(vec![
                                one_of(vec![
                                    Sequence::new(vec![
                                        Ref::new("ColumnReferenceSegment").to_matchable(),
                                        Ref::new("EqualsSegment").to_matchable(),
                                        one_of(vec![
                                            Ref::new("ExpressionSegment").to_matchable(),
                                            Ref::keyword("DEFAULT").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Bracketed::new(vec![
                                            Delimited::new(vec![
                                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                        Ref::new("EqualsSegment").to_matchable(),
                                        Ref::keyword("ROW").optional().to_matchable(),
                                        Bracketed::new(vec![
                                            Delimited::new(vec![
                                                one_of(vec![
                                                    Ref::new("ExpressionSegment").to_matchable(),
                                                    Ref::keyword("DEFAULT").to_matchable(),
                                                ])
                                                .to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Bracketed::new(vec![
                                            Delimited::new(vec![
                                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                        Ref::new("EqualsSegment").to_matchable(),
                                        Bracketed::new(vec![
                                            Ref::new("SelectableGrammar").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("WHERE").to_matchable(),
                                Ref::new("ExpressionSegment").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ConflictTargetSegment".into(),
            NodeMatcher::new(SyntaxKind::ConflictTarget, |_| {
                one_of(vec![
                    Sequence::new(vec![
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                Sequence::new(vec![
                                    one_of(vec![
                                        Ref::new("ColumnReferenceSegment").to_matchable(),
                                        Bracketed::new(vec![
                                            Ref::new("ExpressionSegment").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("COLLATE").to_matchable(),
                                        Ref::new("CollationReferenceSegment").to_matchable(),
                                    ])
                                    .config(|this| this.optional())
                                    .to_matchable(),
                                    Ref::new("OperationClassReferenceSegment")
                                        .optional()
                                        .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("WHERE").to_matchable(),
                            Ref::new("ExpressionSegment").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("ON").to_matchable(),
                        Ref::keyword("CONSTRAINT").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "InsertStatementSegment",
        Sequence::new(vec![
            Ref::keyword("INSERT").to_matchable(),
            Ref::keyword("INTO").to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            Ref::new("AsAliasExpressionSegment")
                .optional()
                .to_matchable(),
            Ref::new("BracketedColumnReferenceListGrammar")
                .optional()
                .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("OVERRIDING").to_matchable(),
                one_of(vec![
                    Ref::keyword("SYSTEM").to_matchable(),
                    Ref::keyword("USER").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("VALUE").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("DEFAULT").to_matchable(),
                    Ref::keyword("VALUES").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("SelectableGrammar").to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("ON").to_matchable(),
                Ref::keyword("CONFLICT").to_matchable(),
                Ref::new("ConflictTargetSegment").optional().to_matchable(),
                Ref::new("ConflictActionSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("RETURNING").to_matchable(),
                MetaSegment::indent().to_matchable(),
                one_of(vec![
                    Ref::new("StarSegment").to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("ExpressionSegment").to_matchable(),
                            Ref::new("AsAliasExpressionSegment")
                                .optional()
                                .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                MetaSegment::dedent().to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "DropTypeStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DROP").to_matchable(),
            Ref::keyword("TYPE").to_matchable(),
            Ref::new("IfExistsGrammar").optional().to_matchable(),
            Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(),
            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "SetStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::SetStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("SET").to_matchable(),
                    one_of(vec![
                        Ref::keyword("SESSION").to_matchable(),
                        Ref::keyword("LOCAL").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::new("ParameterNameSegment").to_matchable(),
                            one_of(vec![
                                Ref::keyword("TO").to_matchable(),
                                Ref::new("EqualsSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            one_of(vec![
                                Ref::keyword("DEFAULT").to_matchable(),
                                Delimited::new(vec![
                                    Ref::new("LiteralGrammar").to_matchable(),
                                    Ref::new("NakedIdentifierSegment").to_matchable(),
                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
                                    Ref::new("OnKeywordAsIdentifierSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("TIME").to_matchable(),
                            Ref::keyword("ZONE").to_matchable(),
                            one_of(vec![
                                Ref::new("QuotedLiteralSegment").to_matchable(),
                                Ref::keyword("LOCAL").to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ROLE").to_matchable(),
                            one_of(vec![
                                Ref::keyword("NONE").to_matchable(),
                                Ref::new("RoleReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreatePolicyStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreatePolicyStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("POLICY").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    Ref::keyword("ON").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("AS").to_matchable(),
                        one_of(vec![
                            Ref::keyword("PERMISSIVE").to_matchable(),
                            Ref::keyword("RESTRICTIVE").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("FOR").to_matchable(),
                        one_of(vec![
                            Ref::keyword("ALL").to_matchable(),
                            Ref::keyword("SELECT").to_matchable(),
                            Ref::keyword("INSERT").to_matchable(),
                            Ref::keyword("UPDATE").to_matchable(),
                            Ref::keyword("DELETE").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("TO").to_matchable(),
                        Delimited::new(vec![
                            one_of(vec![
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                                Ref::keyword("PUBLIC").to_matchable(),
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("USING").to_matchable(),
                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("WITH").to_matchable(),
                        Ref::keyword("CHECK").to_matchable(),
                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CallStoredProcedureSegment".into(),
            NodeMatcher::new(SyntaxKind::CallStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CALL").to_matchable(),
                    Ref::new("FunctionSegment").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateDomainStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateDomainStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("DOMAIN").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    Sequence::new(vec![Ref::keyword("AS").to_matchable()])
                        .config(|this| this.optional())
                        .to_matchable(),
                    Ref::new("DatatypeSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("COLLATE").to_matchable(),
                        Ref::new("CollationReferenceSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("DEFAULT").to_matchable(),
                        Ref::new("ExpressionSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    AnyNumberOf::new(vec![
                        Sequence::new(vec![
                            Sequence::new(vec![
                                Ref::keyword("CONSTRAINT").to_matchable(),
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    Ref::keyword("NOT").optional().to_matchable(),
                                    Ref::keyword("NULL").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("CHECK").to_matchable(),
                                    Ref::new("ExpressionSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterDomainStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterDomainStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("DOMAIN").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("DEFAULT").to_matchable(),
                            Ref::new("ExpressionSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("DROP").to_matchable(),
                            Ref::keyword("DEFAULT").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            one_of(vec![
                                Ref::keyword("SET").to_matchable(),
                                Ref::keyword("DROP").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("NOT").to_matchable(),
                            Ref::keyword("NULL").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ADD").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("CONSTRAINT").to_matchable(),
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                            one_of(vec![
                                Sequence::new(vec![
                                    Ref::keyword("NOT").optional().to_matchable(),
                                    Ref::keyword("NULL").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("CHECK").to_matchable(),
                                    Ref::new("ExpressionSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("NOT").to_matchable(),
                                Ref::keyword("VALID").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("DROP").to_matchable(),
                            Ref::keyword("CONSTRAINT").to_matchable(),
                            Ref::new("IfExistsGrammar").optional().to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                            one_of(vec![
                                Ref::keyword("RESTRICT").to_matchable(),
                                Ref::keyword("CASCADE").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("CONSTRAINT").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("VALIDATE").to_matchable(),
                            Ref::keyword("CONSTRAINT").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DropDomainStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropDomainStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("DOMAIN").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
                        .to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DropPolicyStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DropPolicyStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DROP").to_matchable(),
                    Ref::keyword("POLICY").to_matchable(),
                    Ref::new("IfExistsGrammar").optional().to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    Ref::keyword("ON").to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "LoadStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::LoadStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("LOAD").to_matchable(),
                    Ref::new("QuotedLiteralSegment").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ResetStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::ResetStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("RESET").to_matchable(),
                    one_of(vec![
                        Ref::keyword("ALL").to_matchable(),
                        Ref::keyword("ROLE").to_matchable(),
                        Ref::new("ParameterNameSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DiscardStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DiscardStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DISCARD").to_matchable(),
                    one_of(vec![
                        Ref::keyword("ALL").to_matchable(),
                        Ref::keyword("PLANS").to_matchable(),
                        Ref::keyword("SEQUENCES").to_matchable(),
                        Ref::keyword("TEMPORARY").to_matchable(),
                        Ref::keyword("TEMP").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ListenStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::ListenStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("LISTEN").to_matchable(),
                    Ref::new("SingleIdentifierGrammar").to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "NotifyStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::NotifyStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("NOTIFY").to_matchable(),
                    Ref::new("SingleIdentifierGrammar").to_matchable(),
                    Sequence::new(vec![
                        Ref::new("CommaSegment").to_matchable(),
                        Ref::new("QuotedLiteralSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "UnlistenStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::UnlistenStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("UNLISTEN").to_matchable(),
                    one_of(vec![
                        Ref::new("SingleIdentifierGrammar").to_matchable(),
                        Ref::new("StarSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "TruncateStatementSegment",
        Sequence::new(vec![
            Ref::keyword("TRUNCATE").to_matchable(),
            Ref::keyword("TABLE").optional().to_matchable(),
            Delimited::new(vec![
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("ONLY").optional().to_matchable(),
                        Ref::new("TableReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::new("TableReferenceSegment").to_matchable(),
                        Ref::new("StarSegment").optional().to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Sequence::new(vec![
                one_of(vec![
                    Ref::keyword("RESTART").to_matchable(),
                    Ref::keyword("CONTINUE").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("IDENTITY").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "CopyStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CopyStatement, |_| {
                let _target_subset = one_of(vec![
                    Ref::new("QuotedLiteralSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("PROGRAM").to_matchable(),
                        Ref::new("QuotedLiteralSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ]);

                let _table_definition = Sequence::new(vec![
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
                            .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ]);

                let _option = Sequence::new(vec![
                    Ref::keyword("WITH").optional().to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            any_set_of(vec![
                                Sequence::new(vec![
                                    Ref::keyword("FORMAT").to_matchable(),
                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FREEZE").to_matchable(),
                                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("DELIMITER").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("NULL").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("HEADER").to_matchable(),
                                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("QUOTE").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("ESCAPE").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FORCE_QUOTE").to_matchable(),
                                    one_of(vec![
                                        Bracketed::new(vec![
                                            Delimited::new(vec![
                                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                        Ref::new("StarSegment").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FORCE_NOT_NULL").to_matchable(),
                                    Bracketed::new(vec![
                                        Delimited::new(vec![
                                            Ref::new("ColumnReferenceSegment").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("FORCE_NULL").to_matchable(),
                                    Bracketed::new(vec![
                                        Delimited::new(vec![
                                            Ref::new("ColumnReferenceSegment").to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("ENCODING").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional());

                Sequence::new(vec![
                    Ref::keyword("COPY").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            _table_definition.clone().to_matchable(),
                            Ref::keyword("FROM").to_matchable(),
                            one_of(vec![
                                _target_subset.clone().to_matchable(),
                                Ref::keyword("STDIN").to_matchable(),
                            ])
                            .to_matchable(),
                            _option.clone().to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("WHERE").to_matchable(),
                                Ref::new("ExpressionSegment").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            one_of(vec![
                                _table_definition.clone().to_matchable(),
                                Bracketed::new(vec![
                                    Ref::new("UnorderedSelectStatementSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                _target_subset.to_matchable(),
                                Ref::keyword("STDOUT").to_matchable(),
                            ])
                            .to_matchable(),
                            _option.to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterSchemaStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("SCHEMA").to_matchable(),
                    Ref::new("SchemaReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("SchemaReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("RoleReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "LockTableStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::LockTableStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("LOCK").to_matchable(),
                    Ref::keyword("TABLE").optional().to_matchable(),
                    Ref::keyword("ONLY").optional().to_matchable(),
                    one_of(vec![
                        Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
                            .to_matchable(),
                        Ref::new("StarSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("IN").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("ACCESS").to_matchable(),
                                Ref::keyword("SHARE").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ROW").to_matchable(),
                                Ref::keyword("SHARE").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ROW").to_matchable(),
                                Ref::keyword("EXCLUSIVE").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SHARE").to_matchable(),
                                Ref::keyword("UPDATE").to_matchable(),
                                Ref::keyword("EXCLUSIVE").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("SHARE").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("SHARE").to_matchable(),
                                Ref::keyword("ROW").to_matchable(),
                                Ref::keyword("EXCLUSIVE").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("EXCLUSIVE").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ACCESS").to_matchable(),
                                Ref::keyword("EXCLUSIVE").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::keyword("MODE").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::keyword("NOWAIT").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ClusterStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::ClusterStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CLUSTER").to_matchable(),
                    Ref::keyword("VERBOSE").optional().to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::new("TableReferenceSegment").to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("USING").to_matchable(),
                                Ref::new("IndexReferenceSegment").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::new("IndexReferenceSegment").to_matchable(),
                            Ref::keyword("ON").to_matchable(),
                            Ref::new("TableReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "LanguageClauseSegment".into(),
            NodeMatcher::new(SyntaxKind::LanguageClause, |_| {
                Sequence::new(vec![
                    Ref::keyword("LANGUAGE").to_matchable(),
                    one_of(vec![
                        Ref::new("NakedIdentifierSegment").to_matchable(),
                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "DoStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::DoStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("DO").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::new("LanguageClauseSegment").optional().to_matchable(),
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                            Ref::new("LanguageClauseSegment").optional().to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "CTEDefinitionSegment",
        Sequence::new(vec![
            Ref::new("SingleIdentifierGrammar").to_matchable(),
            Ref::new("CTEColumnList").optional().to_matchable(),
            Ref::keyword("AS").to_matchable(),
            Sequence::new(vec![
                Ref::keyword("NOT").optional().to_matchable(),
                Ref::keyword("MATERIALIZED").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
                .config(|this| this.parse_mode = ParseMode::Greedy)
                .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("SEARCH").to_matchable(),
                    one_of(vec![
                        Ref::keyword("BREADTH").to_matchable(),
                        Ref::keyword("DEPTH").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("FIRST").to_matchable(),
                    Ref::keyword("BY").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                    Ref::keyword("SET").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("CYCLE").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                    Ref::keyword("SET").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                    Ref::keyword("USING").to_matchable(),
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "ValuesClauseSegment",
        Sequence::new(vec![
            Ref::keyword("VALUES").to_matchable(),
            Delimited::new(vec![
                Bracketed::new(vec![
                    Delimited::new(vec![
                        Ref::new("ExpressionSegment").to_matchable(),
                        Ref::keyword("DEFAULT").to_matchable(),
                    ])
                    .config(|this| this.parse_mode = ParseMode::Greedy)
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable(),
            Ref::new("AliasExpressionSegment").optional().to_matchable(),
            Ref::new("OrderByClauseSegment").optional().to_matchable(),
            Ref::new("LimitClauseSegment").optional().to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.replace_grammar(
        "DeleteStatementSegment",
        Sequence::new(vec![
            Ref::keyword("DELETE").to_matchable(),
            Ref::keyword("FROM").to_matchable(),
            Ref::keyword("ONLY").optional().to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            Ref::new("StarSegment").optional().to_matchable(),
            Ref::new("AliasExpressionSegment").optional().to_matchable(),
            Sequence::new(vec![
                Ref::keyword("USING").to_matchable(),
                MetaSegment::indent().to_matchable(),
                Delimited::new(vec![
                    Sequence::new(vec![
                        Ref::new("TableExpressionSegment").to_matchable(),
                        Ref::new("AliasExpressionSegment").optional().to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                MetaSegment::dedent().to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("WHERE").to_matchable(),
                    Ref::keyword("CURRENT").to_matchable(),
                    Ref::keyword("OF").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                ])
                .to_matchable(),
                Ref::new("WhereClauseSegment").to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
            Sequence::new(vec![
                Ref::keyword("RETURNING").to_matchable(),
                MetaSegment::indent().to_matchable(),
                one_of(vec![
                    Ref::new("StarSegment").to_matchable(),
                    Delimited::new(vec![
                        Sequence::new(vec![
                            Ref::new("ExpressionSegment").to_matchable(),
                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                MetaSegment::dedent().to_matchable(),
            ])
            .config(|this| this.optional())
            .to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([
        (
            "SetClauseSegment".into(),
            NodeMatcher::new(SyntaxKind::SetClause, |_| {
                Sequence::new(vec![
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::new("ColumnReferenceSegment").to_matchable(),
                            Ref::new("ArrayAccessorSegment").optional().to_matchable(),
                            Ref::new("EqualsSegment").to_matchable(),
                            one_of(vec![
                                Ref::new("LiteralGrammar").to_matchable(),
                                Ref::new("BareFunctionSegment").to_matchable(),
                                Ref::new("FunctionSegment").to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Ref::new("ExpressionSegment").to_matchable(),
                                Ref::keyword("DEFAULT").to_matchable(),
                            ])
                            .to_matchable(),
                            AnyNumberOf::new(vec![Ref::new("ShorthandCastSegment").to_matchable()])
                                .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Bracketed::new(vec![
                                Delimited::new(vec![
                                    Ref::new("ColumnReferenceSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::new("EqualsSegment").to_matchable(),
                            Bracketed::new(vec![
                                one_of(vec![
                                    Ref::new("SelectableGrammar").to_matchable(),
                                    Delimited::new(vec![
                                        Sequence::new(vec![
                                            one_of(vec![
                                                Ref::new("LiteralGrammar").to_matchable(),
                                                Ref::new("BareFunctionSegment").to_matchable(),
                                                Ref::new("FunctionSegment").to_matchable(),
                                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                                Ref::new("ExpressionSegment").to_matchable(),
                                                Ref::keyword("DEFAULT").to_matchable(),
                                            ])
                                            .to_matchable(),
                                            AnyNumberOf::new(vec![
                                                Ref::new("ShorthandCastSegment").to_matchable(),
                                            ])
                                            .to_matchable(),
                                        ])
                                        .to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "UpdateStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::UpdateStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("UPDATE").to_matchable(),
                    Ref::keyword("ONLY").optional().to_matchable(),
                    Ref::new("TableReferenceSegment").to_matchable(),
                    Ref::new("AliasExpressionSegment")
                        .exclude(Ref::keyword("SET"))
                        .optional()
                        .to_matchable(),
                    Ref::new("SetClauseListSegment").to_matchable(),
                    Ref::new("FromClauseSegment").optional().to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("WHERE").to_matchable(),
                            Ref::keyword("CURRENT").to_matchable(),
                            Ref::keyword("OF").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Ref::new("WhereClauseSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RETURNING").to_matchable(),
                        MetaSegment::indent().to_matchable(),
                        one_of(vec![
                            Ref::new("StarSegment").to_matchable(),
                            Delimited::new(vec![
                                Sequence::new(vec![
                                    Ref::new("ExpressionSegment").to_matchable(),
                                    Ref::new("AliasExpressionSegment").optional().to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        MetaSegment::dedent().to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateTypeStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateTypeStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("TYPE").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("AS").to_matchable(),
                        one_of(vec![
                            Ref::keyword("ENUM").to_matchable(),
                            Ref::keyword("RANGE").to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Bracketed::new(vec![
                        Delimited::new(vec![
                            one_of(vec![
                                Sequence::new(vec![
                                    Ref::new("ColumnReferenceSegment").to_matchable(),
                                    Ref::new("DatatypeSegment").to_matchable(),
                                    Sequence::new(vec![
                                        Ref::keyword("COLLATE").to_matchable(),
                                        Ref::new("CollationReferenceSegment").to_matchable(),
                                    ])
                                    .config(|this| this.optional())
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Anything::new().to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .config(|this| this.optional())
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "AlterTypeStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::AlterTypeStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("ALTER").to_matchable(),
                    Ref::keyword("TYPE").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    one_of(vec![
                        Sequence::new(vec![
                            Ref::keyword("OWNER").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            one_of(vec![
                                Ref::keyword("CURRENT_USER").to_matchable(),
                                Ref::keyword("SESSION_USER").to_matchable(),
                                Ref::keyword("CURRENT_ROLE").to_matchable(),
                                Ref::new("ObjectReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("VALUE").to_matchable(),
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("RENAME").to_matchable(),
                            Ref::keyword("TO").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("SET").to_matchable(),
                            Ref::keyword("SCHEMA").to_matchable(),
                            Ref::new("SchemaReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                        Delimited::new(vec![
                            Sequence::new(vec![
                                Ref::keyword("ADD").to_matchable(),
                                Ref::keyword("ATTRIBUTE").to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Ref::new("DatatypeSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("COLLATE").to_matchable(),
                                    Ref::new("CollationReferenceSegment").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("ALTER").to_matchable(),
                                Ref::keyword("ATTRIBUTE").to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("SET").to_matchable(),
                                    Ref::keyword("DATA").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                Ref::keyword("TYPE").to_matchable(),
                                Ref::new("DatatypeSegment").to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("COLLATE").to_matchable(),
                                    Ref::new("CollationReferenceSegment").to_matchable(),
                                ])
                                .config(|this| this.optional())
                                .to_matchable(),
                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("DROP").to_matchable(),
                                Ref::keyword("ATTRIBUTE").to_matchable(),
                                Ref::new("IfExistsGrammar").optional().to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("RENAME").to_matchable(),
                                Ref::keyword("ATTRIBUTE").to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Ref::keyword("TO").to_matchable(),
                                Ref::new("ColumnReferenceSegment").to_matchable(),
                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("ADD").to_matchable(),
                            Ref::keyword("VALUE").to_matchable(),
                            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                            Ref::new("QuotedLiteralSegment").to_matchable(),
                            Sequence::new(vec![
                                one_of(vec![
                                    Ref::keyword("BEFORE").to_matchable(),
                                    Ref::keyword("AFTER").to_matchable(),
                                ])
                                .to_matchable(),
                                Ref::new("QuotedLiteralSegment").to_matchable(),
                            ])
                            .config(|this| this.optional())
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateCollationStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateCollationStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("COLLATION").to_matchable(),
                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    one_of(vec![
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                Sequence::new(vec![
                                    Ref::keyword("LOCALE").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("LC_COLLATE").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("LC_CTYPE").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("PROVIDER").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                    one_of(vec![
                                        Ref::keyword("ICU").to_matchable(),
                                        Ref::keyword("LIBC").to_matchable(),
                                    ])
                                    .to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("DETERMINISTIC").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                    Ref::new("BooleanLiteralGrammar").to_matchable(),
                                ])
                                .to_matchable(),
                                Sequence::new(vec![
                                    Ref::keyword("VERSION").to_matchable(),
                                    Ref::new("EqualsSegment").to_matchable(),
                                    Ref::new("QuotedLiteralSegment").to_matchable(),
                                ])
                                .to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                        Sequence::new(vec![
                            Ref::keyword("FROM").to_matchable(),
                            Ref::new("ObjectReferenceSegment").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
    ]);

    postgres.replace_grammar(
        "ColumnReferenceSegment",
        Sequence::new(vec![
            Ref::new("SingleIdentifierGrammar").to_matchable(),
            Sequence::new(vec![
                one_of(vec![
                    Ref::new("DotSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::new("DotSegment").to_matchable(),
                        Ref::new("DotSegment").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
                Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()])
                    .config(|this| {
                        this.delimiter(one_of(vec![
                            Ref::new("DotSegment").to_matchable(),
                            Sequence::new(vec![
                                Ref::new("DotSegment").to_matchable(),
                                Ref::new("DotSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ]));
                        this.terminators = vec![
                            Ref::keyword("ON").to_matchable(),
                            Ref::keyword("AS").to_matchable(),
                            Ref::keyword("USING").to_matchable(),
                            Ref::new("CommaSegment").to_matchable(),
                            Ref::new("CastOperatorSegment").to_matchable(),
                            Ref::new("StartSquareBracketSegment").to_matchable(),
                            Ref::new("StartBracketSegment").to_matchable(),
                            Ref::new("BinaryOperatorGrammar").to_matchable(),
                            Ref::new("ColonSegment").to_matchable(),
                            Ref::new("DelimiterGrammar").to_matchable(),
                            Ref::new("JoinLikeClauseGrammar").to_matchable(),
                            Bracketed::new(vec![]).to_matchable(),
                        ];
                        this.allow_gaps = false;
                    })
                    .to_matchable(),
            ])
            .config(|this| {
                this.optional();
                this.allow_gaps = false
            })
            .to_matchable(),
        ])
        .config(|this| this.allow_gaps = false)
        .to_matchable(),
    );

    postgres.add([(
        "NamedArgumentSegment".into(),
        NodeMatcher::new(SyntaxKind::NamedArgument, |_| {
            Sequence::new(vec![
                Ref::new("NakedIdentifierSegment").to_matchable(),
                Ref::new("RightArrowSegment").to_matchable(),
                Ref::new("ExpressionSegment").to_matchable(),
            ])
            .to_matchable()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.replace_grammar(
        "TableExpressionSegment",
        one_of(vec![
            Ref::new("ValuesClauseSegment").to_matchable(),
            Ref::new("BareFunctionSegment").to_matchable(),
            Sequence::new(vec![
                Ref::new("FunctionSegment").to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("ORDINALITY").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable(),
            Ref::new("TableReferenceSegment").to_matchable(),
            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(),
            Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]).to_matchable(),
        ])
        .to_matchable(),
    );

    postgres.add([(
        "ServerReferenceSegment".into(),
        NodeMatcher::new(SyntaxKind::ServerReference, |postgres| {
            postgres
                .grammar("ObjectReferenceSegment")
                .match_grammar(postgres)
                .unwrap()
        })
        .to_matchable()
        .into(),
    )]);

    postgres.add([
        (
            "CreateServerStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateServerStatement, |_| {
                Sequence::new(vec![
                    Ref::keyword("CREATE").to_matchable(),
                    Ref::keyword("SERVER").to_matchable(),
                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                    Ref::new("ServerReferenceSegment").to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("TYPE").to_matchable(),
                        Ref::new("QuotedLiteralSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("VERSION").to_matchable(),
                        Ref::new("VersionIdentifierSegment").to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::new("ForeignDataWrapperGrammar").to_matchable(),
                    Ref::new("ObjectReferenceSegment").to_matchable(),
                    Ref::new("OptionsGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "CreateUserMappingStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::CreateUserMappingStatement, |_| {
                Sequence::new(vec![
                    Ref::new("CreateUserMappingGrammar").to_matchable(),
                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                    Ref::keyword("FOR").to_matchable(),
                    one_of(vec![
                        Ref::new("SingleIdentifierGrammar").to_matchable(),
                        Ref::new("SessionInformationUserFunctionsGrammar").to_matchable(),
                        Ref::keyword("PUBLIC").to_matchable(),
                    ])
                    .to_matchable(),
                    Ref::keyword("SERVER").to_matchable(),
                    Ref::new("ServerReferenceSegment").to_matchable(),
                    Ref::new("OptionsGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            "ImportForeignSchemaStatementSegment".into(),
            NodeMatcher::new(SyntaxKind::ImportForeignSchemaStatement, |_| {
                Sequence::new(vec![
                    Ref::new("ImportForeignSchemaGrammar").to_matchable(),
                    Ref::new("SchemaReferenceSegment").to_matchable(),
                    Sequence::new(vec![
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("LIMIT").to_matchable(),
                                Ref::keyword("TO").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("EXCEPT").to_matchable(),
                        ])
                        .to_matchable(),
                        Bracketed::new(vec![
                            Delimited::new(vec![
                                Ref::new("NakedIdentifierFullSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .config(|this| this.optional())
                    .to_matchable(),
                    Ref::keyword("FROM").to_matchable(),
                    Ref::keyword("SERVER").to_matchable(),
                    Ref::new("ServerReferenceSegment").to_matchable(),
                    Ref::keyword("INTO").to_matchable(),
                    Ref::new("SchemaReferenceSegment").to_matchable(),
                    Ref::new("OptionsGrammar").optional().to_matchable(),
                ])
                .to_matchable()
            })
            .to_matchable()
            .into(),
        ),
        (
            // Statics Reference
            "StatisticsReferenceSegment".into(),
            Ref::new("ObjectReferenceSegment").to_matchable().into(),
        ),
        (
            // Create Statistics Segment.
            // As specified in https://www.postgresql.org/docs/16/sql-createstatistics.html
            "CreateStatisticsStatementSegment".into(),
            Sequence::new(vec![
                Ref::keyword("CREATE").to_matchable(),
                Ref::keyword("STATISTICS").to_matchable(),
                Sequence::new(vec![
                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
                    Ref::new("StatisticsReferenceSegment").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                Bracketed::new(vec![
                    Delimited::new(vec![
                        Ref::keyword("DEPENDENCIES").to_matchable(),
                        Ref::keyword("MCV").to_matchable(),
                        Ref::keyword("NDISTINCT").to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
                Ref::keyword("ON").to_matchable(),
                Delimited::new(vec![
                    Ref::new("ColumnReferenceSegment").to_matchable(),
                    Ref::new("ExpressionSegment").to_matchable(),
                ])
                .to_matchable(),
                Ref::keyword("FROM").to_matchable(),
                Ref::new("TableReferenceSegment").to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            // Alter Statistics Segment.
            // As specified in https://www.postgresql.org/docs/16/sql-alterstatistics.html
            "AlterStatisticsStatementSegment".into(),
            Sequence::new(vec![
                Ref::keyword("ALTER").to_matchable(),
                Ref::keyword("STATISTICS").to_matchable(),
                Ref::new("StatisticsReferenceSegment").to_matchable(),
                one_of(vec![
                    Sequence::new(vec![
                        Ref::keyword("OWNER").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        one_of(vec![
                            one_of(vec![
                                Ref::new("ParameterNameSegment").to_matchable(),
                                Ref::new("QuotedIdentifierSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Ref::keyword("CURRENT_ROLE").to_matchable(),
                            Ref::keyword("CURRENT_USER").to_matchable(),
                            Ref::keyword("SESSION_USER").to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("RENAME").to_matchable(),
                        Ref::keyword("TO").to_matchable(),
                        Ref::new("StatisticsReferenceSegment").to_matchable(),
                    ])
                    .to_matchable(),
                    Sequence::new(vec![
                        Ref::keyword("SET").to_matchable(),
                        one_of(vec![
                            Sequence::new(vec![
                                Ref::keyword("SCHEMA").to_matchable(),
                                Ref::new("SchemaReferenceSegment").to_matchable(),
                            ])
                            .to_matchable(),
                            Sequence::new(vec![
                                Ref::keyword("STATISTICS").to_matchable(),
                                Ref::new("NumericLiteralSegment").to_matchable(),
                            ])
                            .to_matchable(),
                        ])
                        .to_matchable(),
                    ])
                    .to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            // Drop Statistics Segment.
            // As specified in https://www.postgresql.org/docs/16/sql-dropstatistics.html
            "DropStatisticsStatementSegment".into(),
            Sequence::new(vec![
                Ref::keyword("DROP").to_matchable(),
                Ref::keyword("STATISTICS").to_matchable(),
                Ref::new("IfExistsGrammar").optional().to_matchable(),
                Delimited::new(vec![Ref::new("StatisticsReferenceSegment").to_matchable()])
                    .to_matchable(),
                one_of(vec![
                    Ref::keyword("CASCADE").to_matchable(),
                    Ref::keyword("RESTRICT").to_matchable(),
                ])
                .config(|this| this.optional())
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
        (
            "AccessStatementSegmentGrantRoleWithOptionGrammar".into(),
            one_of(vec![
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("GRANT").to_matchable(),
                    Ref::keyword("OPTION").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("ADMIN").to_matchable(),
                    Ref::keyword("OPTION").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("WITH").to_matchable(),
                    Ref::keyword("ADMIN").to_matchable(),
                    Ref::new("BooleanLiteralGrammar").to_matchable(),
                ])
                .to_matchable(),
                Sequence::new(vec![
                    Ref::keyword("COPY").to_matchable(),
                    Ref::keyword("CURRENT").to_matchable(),
                    Ref::keyword("GRANTS").to_matchable(),
                ])
                .to_matchable(),
            ])
            .to_matchable()
            .into(),
        ),
    ]);

    postgres
}

pub fn statement_segment() -> Matchable {
    ansi::statement_segment().copy(
        Some(vec![
            Ref::new("CreateStatisticsStatementSegment").to_matchable(),
            Ref::new("AlterStatisticsStatementSegment").to_matchable(),
            Ref::new("DropStatisticsStatementSegment").to_matchable(),
            Ref::new("AlterDefaultPrivilegesStatementSegment").to_matchable(),
            Ref::new("DropOwnedStatementSegment").to_matchable(),
            Ref::new("ReassignOwnedStatementSegment").to_matchable(),
            Ref::new("CommentOnStatementSegment").to_matchable(),
            Ref::new("AnalyzeStatementSegment").to_matchable(),
            Ref::new("CreateTableAsStatementSegment").to_matchable(),
            Ref::new("AlterTriggerStatementSegment").to_matchable(),
            Ref::new("AlterAggregateStatementSegment").to_matchable(),
            Ref::new("SetStatementSegment").to_matchable(),
            Ref::new("AlterPolicyStatementSegment").to_matchable(),
            Ref::new("CreatePolicyStatementSegment").to_matchable(),
            Ref::new("DropPolicyStatementSegment").to_matchable(),
            Ref::new("CreateDomainStatementSegment").to_matchable(),
            Ref::new("AlterDomainStatementSegment").to_matchable(),
            Ref::new("DropDomainStatementSegment").to_matchable(),
            Ref::new("CreateMaterializedViewStatementSegment").to_matchable(),
            Ref::new("AlterMaterializedViewStatementSegment").to_matchable(),
            Ref::new("DropMaterializedViewStatementSegment").to_matchable(),
            Ref::new("RefreshMaterializedViewStatementSegment").to_matchable(),
            Ref::new("AlterDatabaseStatementSegment").to_matchable(),
            Ref::new("DropDatabaseStatementSegment").to_matchable(),
            Ref::new("VacuumStatementSegment").to_matchable(),
            Ref::new("AlterFunctionStatementSegment").to_matchable(),
            Ref::new("CreateViewStatementSegment").to_matchable(),
            Ref::new("AlterViewStatementSegment").to_matchable(),
            Ref::new("ListenStatementSegment").to_matchable(),
            Ref::new("NotifyStatementSegment").to_matchable(),
            Ref::new("UnlistenStatementSegment").to_matchable(),
            Ref::new("LoadStatementSegment").to_matchable(),
            Ref::new("ResetStatementSegment").to_matchable(),
            Ref::new("DiscardStatementSegment").to_matchable(),
            Ref::new("AlterProcedureStatementSegment").to_matchable(),
            Ref::new("CreateProcedureStatementSegment").to_matchable(),
            Ref::new("DropProcedureStatementSegment").to_matchable(),
            Ref::new("CopyStatementSegment").to_matchable(),
            Ref::new("DoStatementSegment").to_matchable(),
            Ref::new("AlterIndexStatementSegment").to_matchable(),
            Ref::new("ReindexStatementSegment").to_matchable(),
            Ref::new("AlterRoleStatementSegment").to_matchable(),
            Ref::new("CreateExtensionStatementSegment").to_matchable(),
            Ref::new("DropExtensionStatementSegment").to_matchable(),
            Ref::new("CreatePublicationStatementSegment").to_matchable(),
            Ref::new("AlterPublicationStatementSegment").to_matchable(),
            Ref::new("DropPublicationStatementSegment").to_matchable(),
            Ref::new("CreateTypeStatementSegment").to_matchable(),
            Ref::new("AlterTypeStatementSegment").to_matchable(),
            Ref::new("AlterSchemaStatementSegment").to_matchable(),
            Ref::new("LockTableStatementSegment").to_matchable(),
            Ref::new("ClusterStatementSegment").to_matchable(),
            Ref::new("CreateCollationStatementSegment").to_matchable(),
            Ref::new("CallStoredProcedureSegment").to_matchable(),
            Ref::new("CreateServerStatementSegment").to_matchable(),
            Ref::new("CreateUserMappingStatementSegment").to_matchable(),
            Ref::new("ImportForeignSchemaStatementSegment").to_matchable(),
        ]),
        None,
        None,
        None,
        vec![],
        false,
    )
}
