Skip to main content

sqruff_lib_dialects/
postgres.rs

1use itertools::Itertools;
2use sqruff_lib_core::dialects::Dialect;
3use sqruff_lib_core::dialects::init::DialectKind;
4use sqruff_lib_core::dialects::syntax::SyntaxKind;
5use sqruff_lib_core::helpers::{Config, ToMatchable};
6use sqruff_lib_core::parser::grammar::anyof::{
7    AnyNumberOf, any_set_of, one_of, optionally_bracketed,
8};
9use sqruff_lib_core::parser::grammar::delimited::Delimited;
10use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence};
11use sqruff_lib_core::parser::grammar::{Anything, Ref};
12use sqruff_lib_core::parser::lexer::Matcher;
13use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait};
14use sqruff_lib_core::parser::node_matcher::NodeMatcher;
15use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser};
16use sqruff_lib_core::parser::segments::generator::SegmentGenerator;
17use sqruff_lib_core::parser::segments::meta::MetaSegment;
18use sqruff_lib_core::parser::types::ParseMode;
19
20use super::ansi;
21use super::postgres_keywords::POSTGRES_POSTGIS_DATATYPE_KEYWORDS;
22use crate::postgres_keywords::{get_keywords, postgres_keywords};
23use sqruff_lib_core::dialects::init::DialectConfig;
24use sqruff_lib_core::value::Value;
25
26sqruff_lib_core::dialect_config!(PostgresDialectConfig {
27    /// Enable parsing of pg_trgm trigram operators
28    pg_trgm: "Enable parsing of pg_trgm trigram operators (%, <%, %>, <->, etc.)",
29    /// Enable parsing of pgvector data types
30    pgvector: "Enable parsing of pgvector data types (VECTOR, HALFVEC, SPARSEVEC)."
31});
32
33pub fn dialect(config: Option<&Value>) -> Dialect {
34    // Parse and validate dialect configuration, falling back to defaults on failure
35    let dialect_config: PostgresDialectConfig = config
36        .map(PostgresDialectConfig::from_value)
37        .unwrap_or_default();
38
39    let mut postgres = raw_dialect();
40
41    if dialect_config.pg_trgm {
42        postgres.insert_lexer_matchers(
43            vec![Matcher::regex(
44                "trgm_operator",
45                r#"(<<<->|<->>>|<<->|<->>|<->|<<%|%>>|%>|<%|%)"#,
46                SyntaxKind::LikeOperator,
47            )],
48            "like_operator",
49        );
50    }
51
52    if dialect_config.pgvector {
53        postgres.replace_grammar("DatatypeSegment", build_datatype_segment_grammar(true));
54
55        // Add pgvector distance operators: <-> (L2), <=> (cosine), <+> (L1), <#> (inner product)
56        postgres.insert_lexer_matchers(
57            vec![Matcher::regex(
58                "pgvector_operator",
59                r#"(<->|<=>|<\+>|<#>)"#,
60                SyntaxKind::PgvectorOperator,
61            )],
62            "greater_than",
63        );
64
65        // Register PgvectorOperatorSegment as a comparison operator
66        postgres.add([(
67            "PgvectorOperatorSegment".into(),
68            TypedParser::new(SyntaxKind::PgvectorOperator, SyntaxKind::ComparisonOperator)
69                .to_matchable()
70                .into(),
71        )]);
72
73        // Extend ComparisonOperatorGrammar to include pgvector operators
74        postgres.replace_grammar(
75            "ComparisonOperatorGrammar",
76            build_comparison_operator_grammar(true),
77        );
78    }
79
80    postgres.config(|dialect| dialect.expand())
81}
82
83/// Build the ComparisonOperatorGrammar, optionally including pgvector operators.
84fn build_comparison_operator_grammar(pgvector: bool) -> Matchable {
85    let mut operators = vec![
86        Ref::new("EqualsSegment").to_matchable(),
87        Ref::new("GreaterThanSegment").to_matchable(),
88        Ref::new("LessThanSegment").to_matchable(),
89        Ref::new("GreaterThanOrEqualToSegment").to_matchable(),
90        Ref::new("LessThanOrEqualToSegment").to_matchable(),
91        Ref::new("NotEqualToSegment").to_matchable(),
92        Ref::new("LikeOperatorSegment").to_matchable(),
93        Sequence::new(vec![
94            Ref::keyword("IS").to_matchable(),
95            Ref::keyword("DISTINCT").to_matchable(),
96            Ref::keyword("FROM").to_matchable(),
97        ])
98        .to_matchable(),
99        Sequence::new(vec![
100            Ref::keyword("IS").to_matchable(),
101            Ref::keyword("NOT").to_matchable(),
102            Ref::keyword("DISTINCT").to_matchable(),
103            Ref::keyword("FROM").to_matchable(),
104        ])
105        .to_matchable(),
106        Ref::new("OverlapSegment").to_matchable(),
107        Ref::new("NotExtendRightSegment").to_matchable(),
108        Ref::new("NotExtendLeftSegment").to_matchable(),
109        Ref::new("AdjacentSegment").to_matchable(),
110    ];
111
112    if pgvector {
113        operators.push(Ref::new("PgvectorOperatorSegment").to_matchable());
114    }
115
116    one_of(operators).to_matchable()
117}
118
119/// Build the DatatypeSegment grammar, optionally including pgvector types.
120fn build_datatype_segment_grammar(pgvector: bool) -> Matchable {
121    let mut known_types: Vec<Matchable> = vec![
122        Ref::keyword("SMALLINT").to_matchable(),
123        Ref::keyword("INTEGER").to_matchable(),
124        Ref::keyword("INT").to_matchable(),
125        Ref::keyword("INT2").to_matchable(),
126        Ref::keyword("INT4").to_matchable(),
127        Ref::keyword("INT8").to_matchable(),
128        Ref::keyword("BIGINT").to_matchable(),
129        Ref::keyword("FLOAT4").to_matchable(),
130        Ref::keyword("FLOAT8").to_matchable(),
131        Ref::keyword("REAL").to_matchable(),
132        Sequence::new(vec![
133            Ref::keyword("DOUBLE").to_matchable(),
134            Ref::keyword("PRECISION").to_matchable(),
135        ])
136        .to_matchable(),
137        Ref::keyword("SMALLSERIAL").to_matchable(),
138        Ref::keyword("SERIAL").to_matchable(),
139        Ref::keyword("SERIAL2").to_matchable(),
140        Ref::keyword("SERIAL4").to_matchable(),
141        Ref::keyword("SERIAL8").to_matchable(),
142        Ref::keyword("BIGSERIAL").to_matchable(),
143        // Numeric types [(precision)]
144        Sequence::new(vec![
145            one_of(vec![Ref::keyword("FLOAT").to_matchable()]).to_matchable(),
146            Ref::new("BracketedArguments").optional().to_matchable(),
147        ])
148        .to_matchable(),
149        // Numeric types [precision ["," scale])]
150        Sequence::new(vec![
151            one_of(vec![
152                Ref::keyword("DECIMAL").to_matchable(),
153                Ref::keyword("NUMERIC").to_matchable(),
154            ])
155            .to_matchable(),
156            Ref::new("BracketedArguments").optional().to_matchable(),
157        ])
158        .to_matchable(),
159        // Monetary type
160        Ref::keyword("MONEY").to_matchable(),
161        // Character types
162        one_of(vec![
163            Sequence::new(vec![
164                one_of(vec![
165                    Ref::keyword("BPCHAR").to_matchable(),
166                    Ref::keyword("CHAR").to_matchable(),
167                    Sequence::new(vec![
168                        Ref::keyword("CHAR").to_matchable(),
169                        Ref::keyword("VARYING").to_matchable(),
170                    ])
171                    .to_matchable(),
172                    Ref::keyword("CHARACTER").to_matchable(),
173                    Sequence::new(vec![
174                        Ref::keyword("CHARACTER").to_matchable(),
175                        Ref::keyword("VARYING").to_matchable(),
176                    ])
177                    .to_matchable(),
178                    Ref::keyword("VARCHAR").to_matchable(),
179                ])
180                .to_matchable(),
181                Ref::new("BracketedArguments").optional().to_matchable(),
182            ])
183            .to_matchable(),
184            Ref::keyword("TEXT").to_matchable(),
185        ])
186        .to_matchable(),
187        // Binary type
188        Ref::keyword("BYTEA").to_matchable(),
189        // Boolean types
190        one_of(vec![
191            Ref::keyword("BOOLEAN").to_matchable(),
192            Ref::keyword("BOOL").to_matchable(),
193        ])
194        .to_matchable(),
195        // Geometric types
196        one_of(vec![
197            Ref::keyword("POINT").to_matchable(),
198            Ref::keyword("LINE").to_matchable(),
199            Ref::keyword("LSEG").to_matchable(),
200            Ref::keyword("BOX").to_matchable(),
201            Ref::keyword("PATH").to_matchable(),
202            Ref::keyword("POLYGON").to_matchable(),
203            Ref::keyword("CIRCLE").to_matchable(),
204        ])
205        .to_matchable(),
206        // Network address types
207        one_of(vec![
208            Ref::keyword("CIDR").to_matchable(),
209            Ref::keyword("INET").to_matchable(),
210            Ref::keyword("MACADDR").to_matchable(),
211            Ref::keyword("MACADDR8").to_matchable(),
212        ])
213        .to_matchable(),
214        // Text search types
215        one_of(vec![
216            Ref::keyword("TSVECTOR").to_matchable(),
217            Ref::keyword("TSQUERY").to_matchable(),
218        ])
219        .to_matchable(),
220        // Bit string types
221        Sequence::new(vec![
222            Ref::keyword("BIT").to_matchable(),
223            one_of(vec![Ref::keyword("VARYING").to_matchable()])
224                .config(|this| this.optional())
225                .to_matchable(),
226            Ref::new("BracketedArguments").optional().to_matchable(),
227        ])
228        .to_matchable(),
229        // UUID type
230        Ref::keyword("UUID").to_matchable(),
231        // XML type
232        Ref::keyword("XML").to_matchable(),
233        // JSON types
234        one_of(vec![
235            Ref::keyword("JSON").to_matchable(),
236            Ref::keyword("JSONB").to_matchable(),
237        ])
238        .to_matchable(),
239        // Range types
240        Ref::keyword("INT4RANGE").to_matchable(),
241        Ref::keyword("INT8RANGE").to_matchable(),
242        Ref::keyword("NUMRANGE").to_matchable(),
243        Ref::keyword("TSRANGE").to_matchable(),
244        Ref::keyword("TSTZRANGE").to_matchable(),
245        Ref::keyword("DATERANGE").to_matchable(),
246        // pg_lsn type
247        Ref::keyword("PG_LSN").to_matchable(),
248    ];
249
250    // pgvector extension types (VECTOR, HALFVEC, SPARSEVEC with optional dimensions)
251    if pgvector {
252        known_types.push(
253            Sequence::new(vec![
254                one_of(vec![
255                    Ref::keyword("VECTOR").to_matchable(),
256                    Ref::keyword("HALFVEC").to_matchable(),
257                    Ref::keyword("SPARSEVEC").to_matchable(),
258                ])
259                .to_matchable(),
260                Ref::new("BracketedArguments").optional().to_matchable(),
261            ])
262            .to_matchable(),
263        );
264    }
265
266    Sequence::new(vec![
267        Sequence::new(vec![
268            Ref::new("SingleIdentifierGrammar").to_matchable(),
269            Ref::new("DotSegment").to_matchable(),
270        ])
271        .config(|this| {
272            this.allow_gaps = false;
273            this.optional();
274        })
275        .to_matchable(),
276        one_of(vec![
277            Ref::new("WellKnownTextGeometrySegment").to_matchable(),
278            Ref::new("DateTimeTypeIdentifier").to_matchable(),
279            Sequence::new(vec![one_of(known_types).to_matchable()]).to_matchable(),
280            Ref::new("DatatypeIdentifierSegment").to_matchable(),
281        ])
282        .to_matchable(),
283        one_of(vec![
284            AnyNumberOf::new(vec![
285                Bracketed::new(vec![
286                    Ref::new("ExpressionSegment").optional().to_matchable(),
287                ])
288                .config(|this| this.bracket_type("square"))
289                .to_matchable(),
290            ])
291            .to_matchable(),
292            Ref::new("ArrayTypeSegment").to_matchable(),
293            Ref::new("SizedArrayTypeSegment").to_matchable(),
294        ])
295        .config(|this| this.optional())
296        .to_matchable(),
297    ])
298    .to_matchable()
299}
300
301pub fn raw_dialect() -> Dialect {
302    let mut postgres = ansi::raw_dialect();
303    postgres.name = DialectKind::Postgres;
304
305    postgres.insert_lexer_matchers(
306        vec![Matcher::string("right_arrow", "=>", SyntaxKind::RightArrow)],
307        "equals",
308    );
309
310    postgres.insert_lexer_matchers(vec![
311        Matcher::legacy(
312            "unicode_single_quote",
313            |s| s.starts_with("U&'"),
314            r"(?s)U&(('')+?(?!')|('.*?(?<!')(?:'')*'(?!')))(\s*UESCAPE\s*'[^0-9A-Fa-f'+\-\s)]')?",
315            SyntaxKind::UnicodeSingleQuote
316        ),
317        Matcher::legacy(
318            "escaped_single_quote",
319            |s| s.starts_with("E'"),
320            r"(?s)E(('')+?(?!')|'.*?((?<!\\)(?:\\\\)*(?<!')(?:'')*|(?<!\\)(?:\\\\)*\\(?<!')(?:'')*')'(?!'))",
321            SyntaxKind::EscapedSingleQuote
322        ),
323        Matcher::regex(
324            "unicode_double_quote",
325            r#"(?s)U&".+?"(\s*UESCAPE\s*\'[^0-9A-Fa-f\'+\-\s)]\')?"#,
326            SyntaxKind::UnicodeDoubleQuote
327        ),
328        Matcher::regex(
329            "json_operator",
330            r#"->>|#>>|->|#>|@>|<@|\?\|_|\?|\?&|#-"#,
331            SyntaxKind::JsonOperator
332        ),
333        Matcher::string(
334            "at",
335            "@",
336            SyntaxKind::At
337        ),
338        Matcher::regex(
339            "bit_string_literal",
340            r#"[bBxX]'[0-9a-fA-F]*'"#,
341            SyntaxKind::BitStringLiteral
342        ),
343    ], "like_operator");
344
345    postgres.insert_lexer_matchers(
346        vec![
347            Matcher::legacy(
348                "meta_command",
349                |s| s.starts_with("\\"),
350                r"\\([^\\\r\n])+((\\\\)|(?=\n)|(?=\r\n))?",
351                SyntaxKind::Comment,
352            ),
353            Matcher::regex(
354                "dollar_numeric_literal",
355                r"\$\d+",
356                SyntaxKind::DollarNumericLiteral,
357            ),
358        ],
359        "word",
360    );
361
362    postgres.patch_lexer_matchers(vec![
363        Matcher::regex("inline_comment", r"(--)[^\n]*", SyntaxKind::InlineComment),
364        Matcher::legacy(
365            "single_quote",
366            |s| s.starts_with("'"),
367            r"(?s)('')+?(?!')|('.*?(?<!')(?:'')*'(?!'))",
368            SyntaxKind::SingleQuote,
369        ),
370        Matcher::regex("double_quote", r#"(?s)".+?""#, SyntaxKind::DoubleQuote),
371        Matcher::regex("word", r"[a-zA-Z_][0-9a-zA-Z_$]*", SyntaxKind::Word),
372    ]);
373
374    let keywords = postgres_keywords();
375    let not_keywords = get_keywords(&keywords, "not-keyword");
376
377    postgres
378        .sets_mut("reserved_keywords")
379        .extend(get_keywords(&keywords, "reserved"));
380    postgres
381        .sets_mut("unreserved_keywords")
382        .extend(get_keywords(&keywords, "non-reserved"));
383
384    postgres
385        .sets_mut("reserved_keywords")
386        .retain(|keyword| !not_keywords.contains(keyword));
387    postgres
388        .sets_mut("unreserved_keywords")
389        .retain(|keyword| !not_keywords.contains(keyword));
390
391    // Add datetime units
392    postgres.sets_mut("datetime_units").extend([
393        "CENTURY",
394        "DECADE",
395        "DOW",
396        "DOY",
397        "EPOCH",
398        "ISODOW",
399        "ISOYEAR",
400        "MICROSECONDS",
401        "MILLENNIUM",
402        "MILLISECONDS",
403        "TIMEZONE",
404        "TIMEZONE_HOUR",
405        "TIMEZONE_MINUTE",
406    ]);
407
408    // Set the bare functions
409    postgres.sets_mut("bare_functions").extend([
410        "CURRENT_TIMESTAMP",
411        "CURRENT_TIME",
412        "CURRENT_DATE",
413        "LOCALTIME",
414        "LOCALTIMESTAMP",
415    ]);
416
417    // Postgres doesn't have a dateadd function
418    // Also according to https://www.postgresql.org/docs/14/functions-datetime.html
419    // It quotes dateparts. So don't need this.
420    postgres.sets_mut("date_part_function_name").clear();
421
422    // In Postgres, UNNEST() returns a "value table", similar to BigQuery
423    postgres
424        .sets_mut("value_table_functions")
425        .extend(["UNNEST", "GENERATE_SERIES"]);
426
427    postgres.add([
428        (
429            "JsonOperatorSegment".into(),
430            TypedParser::new(SyntaxKind::JsonOperator, SyntaxKind::BinaryOperator)
431                .to_matchable()
432                .into(),
433        ),
434        (
435            "SimpleGeometryGrammar".into(),
436            AnyNumberOf::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
437                .to_matchable()
438                .into(),
439        ),
440        (
441            "MultilineConcatenateNewline".into(),
442            TypedParser::new(SyntaxKind::Newline, SyntaxKind::Newline)
443                .to_matchable()
444                .into(),
445        ),
446        (
447            "MultilineConcatenateDelimiterGrammar".into(),
448            AnyNumberOf::new(vec![Ref::new("MultilineConcatenateNewline").to_matchable()])
449                .config(|this| {
450                    this.min_times(1);
451                    this.disallow_gaps();
452                })
453                .to_matchable()
454                .into(),
455        ),
456        (
457            "NakedIdentifierFullSegment".into(),
458            TypedParser::new(SyntaxKind::Word, SyntaxKind::NakedIdentifier)
459                .to_matchable()
460                .into(),
461        ),
462        (
463            "PropertiesNakedIdentifierSegment".into(),
464            TypedParser::new(SyntaxKind::Word, SyntaxKind::PropertiesNakedIdentifier)
465                .to_matchable()
466                .into(),
467        ),
468        (
469            "SingleIdentifierFullGrammar".into(),
470            one_of(vec![
471                Ref::new("NakedIdentifierSegment").to_matchable(),
472                Ref::new("QuotedIdentifierSegment").to_matchable(),
473                Ref::new("NakedIdentifierFullSegment").to_matchable(),
474            ])
475            .to_matchable()
476            .into(),
477        ),
478        (
479            "DefinitionArgumentValueGrammar".into(),
480            one_of(vec![
481                Ref::new("LiteralGrammar").to_matchable(),
482                Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
483            ])
484            .to_matchable()
485            .into(),
486        ),
487        (
488            "CascadeRestrictGrammar".into(),
489            one_of(vec![
490                Ref::keyword("CASCADE").to_matchable(),
491                Ref::keyword("RESTRICT").to_matchable(),
492            ])
493            .to_matchable()
494            .into(),
495        ),
496        (
497            "ExtendedTableReferenceGrammar".into(),
498            one_of(vec![
499                Ref::new("TableReferenceSegment").to_matchable(),
500                Sequence::new(vec![
501                    Ref::keyword("ONLY").to_matchable(),
502                    optionally_bracketed(vec![Ref::new("TableReferenceSegment").to_matchable()])
503                        .to_matchable(),
504                ])
505                .to_matchable(),
506                Sequence::new(vec![
507                    Ref::new("TableReferenceSegment").to_matchable(),
508                    Ref::new("StarSegment").to_matchable(),
509                ])
510                .to_matchable(),
511            ])
512            .to_matchable()
513            .into(),
514        ),
515        (
516            "RightArrowSegment".into(),
517            StringParser::new("=>", SyntaxKind::RightArrow)
518                .to_matchable()
519                .into(),
520        ),
521        (
522            "OnKeywordAsIdentifierSegment".into(),
523            StringParser::new("ON", SyntaxKind::NakedIdentifier)
524                .to_matchable()
525                .into(),
526        ),
527        (
528            "DollarNumericLiteralSegment".into(),
529            TypedParser::new(
530                SyntaxKind::DollarNumericLiteral,
531                SyntaxKind::DollarNumericLiteral,
532            )
533            .to_matchable()
534            .into(),
535        ),
536        (
537            "ForeignDataWrapperGrammar".into(),
538            Sequence::new(vec![
539                Ref::keyword("FOREIGN").to_matchable(),
540                Ref::keyword("DATA").to_matchable(),
541                Ref::keyword("WRAPPER").to_matchable(),
542            ])
543            .to_matchable()
544            .into(),
545        ),
546        (
547            "OptionsListGrammar".into(),
548            Sequence::new(vec![
549                Delimited::new(vec![
550                    Ref::new("NakedIdentifierFullSegment").to_matchable(),
551                    Ref::new("QuotedLiteralSegment").to_matchable(),
552                ])
553                .to_matchable(),
554            ])
555            .to_matchable()
556            .into(),
557        ),
558        (
559            "OptionsGrammar".into(),
560            Sequence::new(vec![
561                Ref::keyword("OPTIONS").to_matchable(),
562                Bracketed::new(vec![
563                    AnyNumberOf::new(vec![Ref::new("OptionsListGrammar").to_matchable()])
564                        .to_matchable(),
565                ])
566                .to_matchable(),
567            ])
568            .to_matchable()
569            .into(),
570        ),
571        (
572            "CreateUserMappingGrammar".into(),
573            Sequence::new(vec![
574                Ref::keyword("CREATE").to_matchable(),
575                Ref::keyword("USER").to_matchable(),
576                Ref::keyword("MAPPING").to_matchable(),
577            ])
578            .to_matchable()
579            .into(),
580        ),
581        (
582            "SessionInformationUserFunctionsGrammar".into(),
583            one_of(vec![
584                Ref::keyword("USER").to_matchable(),
585                Ref::keyword("CURRENT_ROLE").to_matchable(),
586                Ref::keyword("CURRENT_USER").to_matchable(),
587                Ref::keyword("SESSION_USER").to_matchable(),
588            ])
589            .to_matchable()
590            .into(),
591        ),
592        (
593            "ImportForeignSchemaGrammar".into(),
594            Sequence::new(vec![
595                Ref::keyword("IMPORT").to_matchable(),
596                Ref::keyword("FOREIGN").to_matchable(),
597                Ref::keyword("SCHEMA").to_matchable(),
598            ])
599            .to_matchable()
600            .into(),
601        ),
602    ]);
603
604    postgres.add([
605        (
606            "LikeGrammar".into(),
607            one_of(vec![
608                Ref::keyword("LIKE").to_matchable(),
609                Ref::keyword("ILIKE").to_matchable(),
610                Sequence::new(vec![
611                    Ref::keyword("SIMILAR").to_matchable(),
612                    Ref::keyword("TO").to_matchable(),
613                ])
614                .to_matchable(),
615            ])
616            .to_matchable()
617            .into(),
618        ),
619        (
620            "StringBinaryOperatorGrammar".into(),
621            one_of(vec![
622                Ref::new("ConcatSegment").to_matchable(),
623                Ref::keyword("COLLATE").to_matchable(),
624            ])
625            .to_matchable()
626            .into(),
627        ),
628        (
629            "ComparisonOperatorGrammar".into(),
630            build_comparison_operator_grammar(false).into(),
631        ),
632        (
633            "NakedIdentifierSegment".into(),
634            SegmentGenerator::new(|dialect| {
635                // Generate the anti-template from the set of reserved keywords
636                let reserved_keywords = dialect.sets("reserved_keywords");
637                let pattern = reserved_keywords.iter().join("|");
638                let anti_template = format!("^({pattern})$");
639
640                RegexParser::new(
641                    r"([A-Z_]+|[0-9]+[A-Z_$])[A-Z0-9_$]*",
642                    SyntaxKind::NakedIdentifier,
643                )
644                .anti_template(&anti_template)
645                .to_matchable()
646            })
647            .into(),
648        ),
649        (
650            "ParameterNameSegment".into(),
651            RegexParser::new(r#"[A-Z_][A-Z0-9_$]*|\"[^\"]*\""#, SyntaxKind::Parameter)
652                .to_matchable()
653                .into(),
654        ),
655        (
656            "FunctionNameIdentifierSegment".into(),
657            RegexParser::new(r"[A-Z_][A-Z0-9_$]*", SyntaxKind::FunctionNameIdentifier)
658                .to_matchable()
659                .into(),
660        ),
661        (
662            "FunctionContentsExpressionGrammar".into(),
663            one_of(vec![
664                Ref::new("ExpressionSegment").to_matchable(),
665                Ref::new("NamedArgumentSegment").to_matchable(),
666            ])
667            .to_matchable()
668            .into(),
669        ),
670        (
671            "QuotedLiteralSegment".into(),
672            one_of(vec![
673                Sequence::new(vec![
674                    TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral)
675                        .to_matchable(),
676                    AnyNumberOf::new(vec![
677                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
678                        TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral)
679                            .to_matchable(),
680                    ])
681                    .to_matchable(),
682                ])
683                .to_matchable(),
684                Sequence::new(vec![
685                    TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral)
686                        .to_matchable(),
687                    AnyNumberOf::new(vec![
688                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
689                        TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral)
690                            .to_matchable(),
691                    ])
692                    .to_matchable(),
693                ])
694                .to_matchable(),
695                Delimited::new(vec![
696                    TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral)
697                        .to_matchable(),
698                    AnyNumberOf::new(vec![
699                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
700                        TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral)
701                            .to_matchable(),
702                    ])
703                    .to_matchable(),
704                ])
705                .to_matchable(),
706                Delimited::new(vec![
707                    TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral)
708                        .to_matchable(),
709                    AnyNumberOf::new(vec![
710                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
711                        TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral)
712                            .to_matchable(),
713                    ])
714                    .to_matchable(),
715                ])
716                .to_matchable(),
717                Delimited::new(vec![
718                    TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral)
719                        .to_matchable(),
720                    AnyNumberOf::new(vec![
721                        Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(),
722                        TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral)
723                            .to_matchable(),
724                    ])
725                    .to_matchable(),
726                ])
727                .to_matchable(),
728            ])
729            .to_matchable()
730            .into(),
731        ),
732        (
733            "QuotedIdentifierSegment".into(),
734            one_of(vec![
735                TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier)
736                    .to_matchable(),
737                TypedParser::new(SyntaxKind::UnicodeDoubleQuote, SyntaxKind::QuotedLiteral)
738                    .to_matchable(),
739            ])
740            .to_matchable()
741            .into(),
742        ),
743        (
744            "PostFunctionGrammar".into(),
745            AnyNumberOf::new(vec![
746                Ref::new("WithinGroupClauseSegment").to_matchable(),
747                Ref::new("OverClauseSegment").to_matchable(),
748                Ref::new("FilterClauseGrammar").to_matchable(),
749            ])
750            .to_matchable()
751            .into(),
752        ),
753        (
754            "BinaryOperatorGrammar".into(),
755            one_of(vec![
756                Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(),
757                Ref::new("StringBinaryOperatorGrammar").to_matchable(),
758                Ref::new("BooleanBinaryOperatorGrammar").to_matchable(),
759                Ref::new("ComparisonOperatorGrammar").to_matchable(),
760                Ref::new("JsonOperatorSegment").to_matchable(),
761            ])
762            .to_matchable()
763            .into(),
764        ),
765        (
766            "FunctionParameterGrammar".into(),
767            Sequence::new(vec![
768                one_of(vec![
769                    Ref::keyword("IN").to_matchable(),
770                    Ref::keyword("OUT").to_matchable(),
771                    Ref::keyword("INOUT").to_matchable(),
772                    Ref::keyword("VARIADIC").to_matchable(),
773                ])
774                .config(|this| this.optional())
775                .to_matchable(),
776                one_of(vec![
777                    Ref::new("DatatypeSegment").to_matchable(),
778                    Sequence::new(vec![
779                        Ref::new("ParameterNameSegment").to_matchable(),
780                        Ref::new("DatatypeSegment").to_matchable(),
781                    ])
782                    .to_matchable(),
783                ])
784                .to_matchable(),
785                Sequence::new(vec![
786                    one_of(vec![
787                        Ref::keyword("DEFAULT").to_matchable(),
788                        Ref::new("EqualsSegment").to_matchable(),
789                    ])
790                    .to_matchable(),
791                    Ref::new("ExpressionSegment").to_matchable(),
792                ])
793                .config(|this| this.optional())
794                .to_matchable(),
795            ])
796            .to_matchable()
797            .into(),
798        ),
799        (
800            "FrameClauseUnitGrammar".into(),
801            one_of(vec![
802                Ref::keyword("RANGE").to_matchable(),
803                Ref::keyword("ROWS").to_matchable(),
804                Ref::keyword("GROUPS").to_matchable(),
805            ])
806            .to_matchable()
807            .into(),
808        ),
809        (
810            "IsNullGrammar".into(),
811            Ref::keyword("ISNULL").to_matchable().into(),
812        ),
813        (
814            "NotNullGrammar".into(),
815            Ref::keyword("NOTNULL").to_matchable().into(),
816        ),
817        (
818            "JoinKeywordsGrammar".into(),
819            Sequence::new(vec![
820                Ref::keyword("JOIN").to_matchable(),
821                Sequence::new(vec![Ref::keyword("LATERAL").to_matchable()])
822                    .config(|this| this.optional())
823                    .to_matchable(),
824            ])
825            .to_matchable()
826            .into(),
827        ),
828        (
829            "SelectClauseTerminatorGrammar".into(),
830            one_of(vec![
831                Ref::keyword("INTO").to_matchable(),
832                Ref::keyword("FROM").to_matchable(),
833                Ref::keyword("WHERE").to_matchable(),
834                Sequence::new(vec![
835                    Ref::keyword("ORDER").to_matchable(),
836                    Ref::keyword("BY").to_matchable(),
837                ])
838                .to_matchable(),
839                Ref::keyword("LIMIT").to_matchable(),
840                Ref::new("CommaSegment").to_matchable(),
841                Ref::new("SetOperatorSegment").to_matchable(),
842            ])
843            .to_matchable()
844            .into(),
845        ),
846        // Assuming the existence of `ansi_dialect` in Rust and a way to manipulate its
847        // grammar:
848        (
849            "LiteralGrammar".into(),
850            postgres
851                .grammar("LiteralGrammar")
852                .copy(
853                    Some(vec![
854                        Ref::new("DollarNumericLiteralSegment").to_matchable(),
855                        Ref::new("PsqlVariableGrammar").to_matchable(),
856                    ]),
857                    None,
858                    Some(Ref::new("ArrayLiteralSegment").to_matchable()),
859                    None,
860                    Vec::new(),
861                    false,
862                )
863                .into(),
864        ),
865        (
866            "FromClauseTerminatorGrammar".into(),
867            postgres
868                .grammar("FromClauseTerminatorGrammar")
869                .copy(
870                    Some(vec![Ref::new("ForClauseSegment").to_matchable()]),
871                    None,
872                    None,
873                    None,
874                    Vec::new(),
875                    false,
876                )
877                .into(),
878        ),
879        (
880            "WhereClauseTerminatorGrammar".into(),
881            one_of(vec![
882                Ref::keyword("LIMIT").to_matchable(),
883                Sequence::new(vec![
884                    Ref::keyword("GROUP").to_matchable(),
885                    Ref::keyword("BY").to_matchable(),
886                ])
887                .to_matchable(),
888                Sequence::new(vec![
889                    Ref::keyword("ORDER").to_matchable(),
890                    Ref::keyword("BY").to_matchable(),
891                ])
892                .to_matchable(),
893                Ref::keyword("HAVING").to_matchable(),
894                Ref::keyword("QUALIFY").to_matchable(),
895                Ref::keyword("WINDOW").to_matchable(),
896                Ref::keyword("OVERLAPS").to_matchable(),
897                Ref::keyword("RETURNING").to_matchable(),
898                Sequence::new(vec![
899                    Ref::keyword("ON").to_matchable(),
900                    Ref::keyword("CONFLICT").to_matchable(),
901                ])
902                .to_matchable(),
903                Ref::new("ForClauseSegment").to_matchable(),
904            ])
905            .to_matchable()
906            .into(),
907        ),
908        (
909            "OrderByClauseTerminators".into(),
910            one_of(vec![
911                Ref::keyword("LIMIT").to_matchable(),
912                Ref::keyword("HAVING").to_matchable(),
913                Ref::keyword("QUALIFY").to_matchable(),
914                Ref::keyword("WINDOW").to_matchable(),
915                Ref::new("FrameClauseUnitGrammar").to_matchable(),
916                Ref::keyword("SEPARATOR").to_matchable(),
917                Sequence::new(vec![
918                    Ref::keyword("WITH").to_matchable(),
919                    Ref::keyword("DATA").to_matchable(),
920                ])
921                .to_matchable(),
922                Ref::new("ForClauseSegment").to_matchable(),
923            ])
924            .to_matchable()
925            .into(),
926        ),
927        (
928            "AccessorGrammar".into(),
929            AnyNumberOf::new(vec![
930                Ref::new("ArrayAccessorSegment").to_matchable(),
931                Ref::new("SemiStructuredAccessorSegment").to_matchable(),
932            ])
933            .to_matchable()
934            .into(),
935        ),
936        (
937            "NonWithSelectableGrammar".into(),
938            one_of(vec![
939                Ref::new("SetExpressionSegment").to_matchable(),
940                optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()])
941                    .to_matchable(),
942                Ref::new("NonSetSelectableGrammar").to_matchable(),
943                Ref::new("UpdateStatementSegment").to_matchable(),
944                Ref::new("InsertStatementSegment").to_matchable(),
945                Ref::new("DeleteStatementSegment").to_matchable(),
946            ])
947            .to_matchable()
948            .into(),
949        ),
950        (
951            "NonWithNonSelectableGrammar".into(),
952            one_of(vec![]).to_matchable().into(),
953        ),
954    ]);
955
956    postgres.add([
957        (
958            "OverlapSegment".into(),
959            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
960                Sequence::new(vec![
961                    Ref::new("AmpersandSegment").to_matchable(),
962                    Ref::new("AmpersandSegment").to_matchable(),
963                ])
964                .to_matchable()
965            })
966            .to_matchable()
967            .into(),
968        ),
969        (
970            "NotExtendRightSegment".into(),
971            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
972                Sequence::new(vec![
973                    Ref::new("AmpersandSegment").to_matchable(),
974                    Ref::new("RawGreaterThanSegment").to_matchable(),
975                ])
976                .allow_gaps(false)
977                .to_matchable()
978            })
979            .to_matchable()
980            .into(),
981        ),
982        (
983            "NotExtendLeftSegment".into(),
984            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
985                Sequence::new(vec![
986                    Ref::new("AmpersandSegment").to_matchable(),
987                    Ref::new("RawLessThanSegment").to_matchable(),
988                ])
989                .allow_gaps(false)
990                .to_matchable()
991            })
992            .to_matchable()
993            .into(),
994        ),
995        (
996            "AdjacentSegment".into(),
997            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
998                Sequence::new(vec![
999                    Ref::new("MinusSegment").to_matchable(),
1000                    Ref::new("PipeSegment").to_matchable(),
1001                    Ref::new("MinusSegment").to_matchable(),
1002                ])
1003                .allow_gaps(false)
1004                .to_matchable()
1005            })
1006            .to_matchable()
1007            .into(),
1008        ),
1009    ]);
1010
1011    postgres.add([(
1012        "PsqlVariableGrammar".into(),
1013        NodeMatcher::new(SyntaxKind::PsqlVariable, |_| {
1014            Sequence::new(vec![
1015                optionally_bracketed(vec![
1016                    Ref::new("ColonSegment").to_matchable(),
1017                    one_of(vec![
1018                        Ref::new("ParameterNameSegment").to_matchable(),
1019                        Ref::new("QuotedLiteralSegment").to_matchable(),
1020                    ])
1021                    .to_matchable(),
1022                ])
1023                .to_matchable(),
1024            ])
1025            .to_matchable()
1026        })
1027        .to_matchable()
1028        .into(),
1029    )]);
1030
1031    postgres.replace_grammar(
1032        "ArrayAccessorSegment",
1033        Bracketed::new(vec![
1034            one_of(vec![
1035                // These three are for a single element access: [n]
1036                Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
1037                Ref::new("NumericLiteralSegment").to_matchable(),
1038                Ref::new("ExpressionSegment").to_matchable(),
1039                // This is for slice access: [n:m], [:m], [n:], and [:]
1040                Sequence::new(vec![
1041                    one_of(vec![
1042                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
1043                        Ref::new("NumericLiteralSegment").to_matchable(),
1044                        Ref::new("ExpressionSegment").to_matchable(),
1045                    ])
1046                    .config(|this| this.optional())
1047                    .to_matchable(),
1048                    Ref::new("SliceSegment").to_matchable(),
1049                    one_of(vec![
1050                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
1051                        Ref::new("NumericLiteralSegment").to_matchable(),
1052                        Ref::new("ExpressionSegment").to_matchable(),
1053                    ])
1054                    .config(|this| this.optional())
1055                    .to_matchable(),
1056                ])
1057                .to_matchable(),
1058            ])
1059            .to_matchable(),
1060        ])
1061        .config(|this| {
1062            this.bracket_type("square");
1063        })
1064        .to_matchable(),
1065    );
1066
1067    postgres.add([(
1068        "DateTimeTypeIdentifier".into(),
1069        NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_| {
1070            one_of(vec![
1071                Ref::keyword("DATE").to_matchable(),
1072                Sequence::new(vec![
1073                    one_of(vec![
1074                        Ref::keyword("TIME").to_matchable(),
1075                        Ref::keyword("TIMESTAMP").to_matchable(),
1076                    ])
1077                    .to_matchable(),
1078                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
1079                        .config(|this| this.optional())
1080                        .to_matchable(),
1081                    Sequence::new(vec![
1082                        one_of(vec![
1083                            Ref::keyword("WITH").to_matchable(),
1084                            Ref::keyword("WITHOUT").to_matchable(),
1085                        ])
1086                        .to_matchable(),
1087                        Ref::keyword("TIME").to_matchable(),
1088                        Ref::keyword("ZONE").to_matchable(),
1089                    ])
1090                    .config(|this| this.optional())
1091                    .to_matchable(),
1092                ])
1093                .to_matchable(),
1094                Sequence::new(vec![
1095                    one_of(vec![
1096                        Ref::keyword("INTERVAL").to_matchable(),
1097                        Ref::keyword("TIMETZ").to_matchable(),
1098                        Ref::keyword("TIMESTAMPTZ").to_matchable(),
1099                    ])
1100                    .to_matchable(),
1101                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
1102                        .config(|this| this.optional())
1103                        .to_matchable(),
1104                ])
1105                .to_matchable(),
1106            ])
1107            .to_matchable()
1108        })
1109        .to_matchable()
1110        .into(),
1111    )]);
1112
1113    postgres.add([(
1114        "DateTimeLiteralGrammar".into(),
1115        NodeMatcher::new(SyntaxKind::DatetimeLiteral, |_| {
1116            Sequence::new(vec![
1117                Ref::new("DateTimeTypeIdentifier").optional().to_matchable(),
1118                Ref::new("QuotedLiteralSegment").to_matchable(),
1119            ])
1120            .to_matchable()
1121        })
1122        .to_matchable()
1123        .into(),
1124    )]);
1125
1126    postgres.replace_grammar("DatatypeSegment", build_datatype_segment_grammar(false));
1127
1128    postgres.replace_grammar("ArrayTypeSegment", Ref::keyword("ARRAY").to_matchable());
1129
1130    postgres.add([(
1131        "IndexAccessMethodSegment".into(),
1132        NodeMatcher::new(SyntaxKind::IndexAccessMethod, |_| {
1133            Ref::new("SingleIdentifierGrammar").to_matchable()
1134        })
1135        .to_matchable()
1136        .into(),
1137    )]);
1138
1139    postgres.add([(
1140        "OperatorClassReferenceSegment".into(),
1141        NodeMatcher::new(SyntaxKind::OperatorClassReference, |postgres| {
1142            postgres
1143                .grammar("ObjectReferenceSegment")
1144                .match_grammar(postgres)
1145                .unwrap()
1146        })
1147        .to_matchable()
1148        .into(),
1149    )]);
1150
1151    postgres.add([
1152        (
1153            "DefinitionParameterSegment".into(),
1154            NodeMatcher::new(SyntaxKind::DefinitionParameter, |_| {
1155                Sequence::new(vec![
1156                    Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
1157                    Sequence::new(vec![
1158                        Ref::new("EqualsSegment").to_matchable(),
1159                        Ref::new("DefinitionArgumentValueGrammar")
1160                            .optional()
1161                            .to_matchable(),
1162                    ])
1163                    .to_matchable(),
1164                ])
1165                .to_matchable()
1166            })
1167            .to_matchable()
1168            .into(),
1169        ),
1170        (
1171            "DefinitionParametersSegment".into(),
1172            NodeMatcher::new(SyntaxKind::DefinitionParameters, |_| {
1173                Bracketed::new(vec![
1174                    Delimited::new(vec![Ref::new("DefinitionParameterSegment").to_matchable()])
1175                        .to_matchable(),
1176                ])
1177                .to_matchable()
1178            })
1179            .to_matchable()
1180            .into(),
1181        ),
1182    ]);
1183
1184    postgres.replace_grammar(
1185        "CreateCastStatementSegment",
1186        Sequence::new(vec![
1187            Ref::keyword("CREATE").to_matchable(),
1188            Ref::keyword("CAST").to_matchable(),
1189            Bracketed::new(vec![
1190                Sequence::new(vec![
1191                    Ref::new("DatatypeSegment").to_matchable(),
1192                    Ref::keyword("AS").to_matchable(),
1193                    Ref::new("DatatypeSegment").to_matchable(),
1194                ])
1195                .to_matchable(),
1196            ])
1197            .to_matchable(),
1198            one_of(vec![
1199                Sequence::new(vec![
1200                    Ref::keyword("WITH").to_matchable(),
1201                    Ref::keyword("FUNCTION").to_matchable(),
1202                    Ref::new("FunctionNameSegment").to_matchable(),
1203                    Ref::new("FunctionParameterListGrammar")
1204                        .optional()
1205                        .to_matchable(),
1206                ])
1207                .to_matchable(),
1208                Sequence::new(vec![
1209                    Ref::keyword("WITHOUT").to_matchable(),
1210                    Ref::keyword("FUNCTION").to_matchable(),
1211                ])
1212                .to_matchable(),
1213                Sequence::new(vec![
1214                    Ref::keyword("WITH").to_matchable(),
1215                    Ref::keyword("INOUT").to_matchable(),
1216                ])
1217                .to_matchable(),
1218            ])
1219            .to_matchable(),
1220            one_of(vec![
1221                Sequence::new(vec![
1222                    Ref::keyword("AS").to_matchable(),
1223                    Ref::keyword("ASSIGNMENT").to_matchable(),
1224                ])
1225                .config(|this| this.optional())
1226                .to_matchable(),
1227                Sequence::new(vec![
1228                    Ref::keyword("AS").to_matchable(),
1229                    Ref::keyword("IMPLICIT").to_matchable(),
1230                ])
1231                .config(|this| this.optional())
1232                .to_matchable(),
1233            ])
1234            .config(|this| this.optional())
1235            .to_matchable(),
1236        ])
1237        .to_matchable(),
1238    );
1239
1240    postgres.replace_grammar(
1241        "DropCastStatementSegment",
1242        Sequence::new(vec![
1243            Ref::keyword("DROP").to_matchable(),
1244            Ref::keyword("CAST").to_matchable(),
1245            Sequence::new(vec![
1246                Ref::keyword("IF").to_matchable(),
1247                Ref::keyword("EXISTS").to_matchable(),
1248            ])
1249            .config(|this| this.optional())
1250            .to_matchable(),
1251            Bracketed::new(vec![
1252                Sequence::new(vec![
1253                    Ref::new("DatatypeSegment").to_matchable(),
1254                    Ref::keyword("AS").to_matchable(),
1255                    Ref::new("DatatypeSegment").to_matchable(),
1256                ])
1257                .to_matchable(),
1258            ])
1259            .to_matchable(),
1260            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
1261        ])
1262        .to_matchable(),
1263    );
1264
1265    postgres.add([
1266        (
1267            "RelationOptionSegment".into(),
1268            NodeMatcher::new(SyntaxKind::RelationOption, |_| {
1269                Sequence::new(vec![
1270                    Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
1271                    Sequence::new(vec![
1272                        Ref::new("DotSegment").to_matchable(),
1273                        Ref::new("PropertiesNakedIdentifierSegment").to_matchable(),
1274                    ])
1275                    .config(|this| this.optional())
1276                    .to_matchable(),
1277                    Sequence::new(vec![
1278                        Ref::new("EqualsSegment").to_matchable(),
1279                        Ref::new("DefinitionArgumentValueGrammar")
1280                            .optional()
1281                            .to_matchable(),
1282                    ])
1283                    .config(|this| this.optional())
1284                    .to_matchable(),
1285                ])
1286                .to_matchable()
1287            })
1288            .to_matchable()
1289            .into(),
1290        ),
1291        (
1292            "RelationOptionsSegment".into(),
1293            NodeMatcher::new(SyntaxKind::RelationOptions, |_| {
1294                Bracketed::new(vec![
1295                    Delimited::new(vec![Ref::new("RelationOptionSegment").to_matchable()])
1296                        .to_matchable(),
1297                ])
1298                .to_matchable()
1299            })
1300            .to_matchable()
1301            .into(),
1302        ),
1303    ]);
1304
1305    postgres.replace_grammar(
1306        "CreateFunctionStatementSegment",
1307        Sequence::new(vec![
1308            Ref::keyword("CREATE").to_matchable(),
1309            Sequence::new(vec![
1310                Ref::keyword("OR").to_matchable(),
1311                Ref::keyword("REPLACE").to_matchable(),
1312            ])
1313            .config(|this| this.optional())
1314            .to_matchable(),
1315            Ref::new("TemporaryGrammar").optional().to_matchable(),
1316            Ref::keyword("FUNCTION").to_matchable(),
1317            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1318            Ref::new("FunctionNameSegment").to_matchable(),
1319            Ref::new("FunctionParameterListGrammar").to_matchable(),
1320            Sequence::new(vec![
1321                Ref::keyword("RETURNS").to_matchable(),
1322                one_of(vec![
1323                    Sequence::new(vec![
1324                        Ref::keyword("TABLE").to_matchable(),
1325                        Bracketed::new(vec![
1326                            Delimited::new(vec![
1327                                one_of(vec![
1328                                    Ref::new("DatatypeSegment").to_matchable(),
1329                                    Sequence::new(vec![
1330                                        Ref::new("ColumnReferenceSegment").to_matchable(),
1331                                        Ref::new("DatatypeSegment").to_matchable(),
1332                                    ])
1333                                    .to_matchable(),
1334                                ])
1335                                .to_matchable(),
1336                            ])
1337                            .to_matchable(),
1338                        ])
1339                        .config(|this| this.optional())
1340                        .to_matchable(),
1341                    ])
1342                    .to_matchable(),
1343                    Sequence::new(vec![
1344                        Ref::keyword("SETOF").to_matchable(),
1345                        Ref::new("DatatypeSegment").to_matchable(),
1346                    ])
1347                    .to_matchable(),
1348                    Ref::new("DatatypeSegment").to_matchable(),
1349                ])
1350                .config(|this| this.optional())
1351                .to_matchable(),
1352            ])
1353            .config(|this| this.optional())
1354            .to_matchable(),
1355            Ref::new("FunctionDefinitionGrammar").to_matchable(),
1356        ])
1357        .to_matchable(),
1358    );
1359
1360    postgres.add([
1361        (
1362            "DropFunctionStatementSegment".into(),
1363            NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| {
1364                Sequence::new(vec![
1365                    Ref::keyword("DROP").to_matchable(),
1366                    Ref::keyword("FUNCTION").to_matchable(),
1367                    Ref::new("IfExistsGrammar").optional().to_matchable(),
1368                    Delimited::new(vec![
1369                        Sequence::new(vec![
1370                            Ref::new("FunctionNameSegment").to_matchable(),
1371                            Ref::new("FunctionParameterListGrammar")
1372                                .optional()
1373                                .to_matchable(),
1374                        ])
1375                        .to_matchable(),
1376                    ])
1377                    .to_matchable(),
1378                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
1379                ])
1380                .to_matchable()
1381            })
1382            .to_matchable()
1383            .into(),
1384        ),
1385        (
1386            "AlterFunctionStatementSegment".into(),
1387            NodeMatcher::new(SyntaxKind::AlterFunctionStatement, |_| {
1388                Sequence::new(vec![
1389                    Ref::keyword("ALTER").to_matchable(),
1390                    Ref::keyword("FUNCTION").to_matchable(),
1391                    Delimited::new(vec![
1392                        Sequence::new(vec![
1393                            Ref::new("FunctionNameSegment").to_matchable(),
1394                            Ref::new("FunctionParameterListGrammar")
1395                                .optional()
1396                                .to_matchable(),
1397                        ])
1398                        .to_matchable(),
1399                    ])
1400                    .to_matchable(),
1401                    one_of(vec![
1402                        Ref::new("AlterFunctionActionSegment")
1403                            .optional()
1404                            .to_matchable(),
1405                        Sequence::new(vec![
1406                            Ref::keyword("RENAME").to_matchable(),
1407                            Ref::keyword("TO").to_matchable(),
1408                            Ref::new("FunctionNameSegment").to_matchable(),
1409                        ])
1410                        .to_matchable(),
1411                        Sequence::new(vec![
1412                            Ref::keyword("SET").to_matchable(),
1413                            Ref::keyword("SCHEMA").to_matchable(),
1414                            Ref::new("SchemaReferenceSegment").to_matchable(),
1415                        ])
1416                        .to_matchable(),
1417                        Sequence::new(vec![
1418                            Ref::keyword("OWNER").to_matchable(),
1419                            Ref::keyword("TO").to_matchable(),
1420                            one_of(vec![
1421                                one_of(vec![
1422                                    Ref::new("ParameterNameSegment").to_matchable(),
1423                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
1424                                ])
1425                                .to_matchable(),
1426                                Ref::keyword("CURRENT_ROLE").to_matchable(),
1427                                Ref::keyword("CURRENT_USER").to_matchable(),
1428                                Ref::keyword("SESSION_USER").to_matchable(),
1429                            ])
1430                            .to_matchable(),
1431                        ])
1432                        .to_matchable(),
1433                        Sequence::new(vec![
1434                            Ref::keyword("NO").optional().to_matchable(),
1435                            Ref::keyword("DEPENDS").to_matchable(),
1436                            Ref::keyword("ON").to_matchable(),
1437                            Ref::keyword("EXTENSION").to_matchable(),
1438                            Ref::new("ExtensionReferenceSegment").to_matchable(),
1439                        ])
1440                        .to_matchable(),
1441                    ])
1442                    .to_matchable(),
1443                ])
1444                .to_matchable()
1445            })
1446            .to_matchable()
1447            .into(),
1448        ),
1449        (
1450            "AlterFunctionActionSegment".into(),
1451            NodeMatcher::new(SyntaxKind::AlterFunctionActionSegment, |_| {
1452                Sequence::new(vec![
1453                    one_of(vec![
1454                        one_of(vec![
1455                            Sequence::new(vec![
1456                                Ref::keyword("CALLED").to_matchable(),
1457                                Ref::keyword("ON").to_matchable(),
1458                                Ref::keyword("NULL").to_matchable(),
1459                                Ref::keyword("INPUT").to_matchable(),
1460                            ])
1461                            .to_matchable(),
1462                            Sequence::new(vec![
1463                                Ref::keyword("RETURNS").to_matchable(),
1464                                Ref::keyword("NULL").to_matchable(),
1465                                Ref::keyword("ON").to_matchable(),
1466                                Ref::keyword("NULL").to_matchable(),
1467                                Ref::keyword("INPUT").to_matchable(),
1468                            ])
1469                            .to_matchable(),
1470                            Ref::keyword("STRICT").to_matchable(),
1471                        ])
1472                        .to_matchable(),
1473                        one_of(vec![
1474                            Ref::keyword("IMMUTABLE").to_matchable(),
1475                            Ref::keyword("STABLE").to_matchable(),
1476                            Ref::keyword("VOLATILE").to_matchable(),
1477                        ])
1478                        .to_matchable(),
1479                        Sequence::new(vec![
1480                            Ref::keyword("NOT").optional().to_matchable(),
1481                            Ref::keyword("LEAKPROOF").to_matchable(),
1482                        ])
1483                        .to_matchable(),
1484                        Sequence::new(vec![
1485                            Ref::keyword("EXTERNAL").optional().to_matchable(),
1486                            Ref::keyword("SECURITY").to_matchable(),
1487                            one_of(vec![
1488                                Ref::keyword("DEFINER").to_matchable(),
1489                                Ref::keyword("INVOKER").to_matchable(),
1490                            ])
1491                            .to_matchable(),
1492                        ])
1493                        .to_matchable(),
1494                        Sequence::new(vec![
1495                            Ref::keyword("PARALLEL").to_matchable(),
1496                            one_of(vec![
1497                                Ref::keyword("UNSAFE").to_matchable(),
1498                                Ref::keyword("RESTRICTED").to_matchable(),
1499                                Ref::keyword("SAFE").to_matchable(),
1500                            ])
1501                            .to_matchable(),
1502                        ])
1503                        .to_matchable(),
1504                        Sequence::new(vec![
1505                            Ref::keyword("COST").to_matchable(),
1506                            Ref::new("NumericLiteralSegment").to_matchable(),
1507                        ])
1508                        .to_matchable(),
1509                        Sequence::new(vec![
1510                            Ref::keyword("ROWS").to_matchable(),
1511                            Ref::new("NumericLiteralSegment").to_matchable(),
1512                        ])
1513                        .to_matchable(),
1514                        Sequence::new(vec![
1515                            Ref::keyword("SUPPORT").to_matchable(),
1516                            Ref::new("ParameterNameSegment").to_matchable(),
1517                        ])
1518                        .to_matchable(),
1519                        Sequence::new(vec![
1520                            Ref::keyword("SET").to_matchable(),
1521                            Ref::new("ParameterNameSegment").to_matchable(),
1522                            one_of(vec![
1523                                Sequence::new(vec![
1524                                    one_of(vec![
1525                                        Ref::keyword("TO").to_matchable(),
1526                                        Ref::new("EqualsSegment").to_matchable(),
1527                                    ])
1528                                    .to_matchable(),
1529                                    one_of(vec![
1530                                        Ref::new("LiteralGrammar").to_matchable(),
1531                                        Ref::new("NakedIdentifierSegment").to_matchable(),
1532                                        Ref::keyword("DEFAULT").to_matchable(),
1533                                    ])
1534                                    .to_matchable(),
1535                                ])
1536                                .to_matchable(),
1537                                Sequence::new(vec![
1538                                    Ref::keyword("FROM").to_matchable(),
1539                                    Ref::keyword("CURRENT").to_matchable(),
1540                                ])
1541                                .to_matchable(),
1542                            ])
1543                            .to_matchable(),
1544                        ])
1545                        .to_matchable(),
1546                        Sequence::new(vec![
1547                            Ref::keyword("RESET").to_matchable(),
1548                            one_of(vec![
1549                                Ref::keyword("ALL").to_matchable(),
1550                                Ref::new("ParameterNameSegment").to_matchable(),
1551                            ])
1552                            .to_matchable(),
1553                        ])
1554                        .to_matchable(),
1555                    ])
1556                    .to_matchable(),
1557                    Ref::keyword("RESTRICT").optional().to_matchable(),
1558                ])
1559                .to_matchable()
1560            })
1561            .to_matchable()
1562            .into(),
1563        ),
1564        (
1565            "AlterProcedureActionSegment".into(),
1566            NodeMatcher::new(SyntaxKind::AlterProcedureActionSegment, |_| {
1567                Sequence::new(vec![
1568                    one_of(vec![
1569                        Sequence::new(vec![
1570                            Ref::keyword("EXTERNAL").optional().to_matchable(),
1571                            Ref::keyword("SECURITY").to_matchable(),
1572                            one_of(vec![
1573                                Ref::keyword("DEFINER").to_matchable(),
1574                                Ref::keyword("INVOKER").to_matchable(),
1575                            ])
1576                            .to_matchable(),
1577                        ])
1578                        .to_matchable(),
1579                        Sequence::new(vec![
1580                            Ref::keyword("SET").to_matchable(),
1581                            Ref::new("ParameterNameSegment").to_matchable(),
1582                            one_of(vec![
1583                                Sequence::new(vec![
1584                                    one_of(vec![
1585                                        Ref::keyword("TO").to_matchable(),
1586                                        Ref::new("EqualsSegment").to_matchable(),
1587                                    ])
1588                                    .to_matchable(),
1589                                    one_of(vec![
1590                                        Ref::new("LiteralGrammar").to_matchable(),
1591                                        Ref::new("NakedIdentifierSegment").to_matchable(),
1592                                        Ref::keyword("DEFAULT").to_matchable(),
1593                                    ])
1594                                    .to_matchable(),
1595                                ])
1596                                .to_matchable(),
1597                                Sequence::new(vec![
1598                                    Ref::keyword("FROM").to_matchable(),
1599                                    Ref::keyword("CURRENT").to_matchable(),
1600                                ])
1601                                .to_matchable(),
1602                            ])
1603                            .to_matchable(),
1604                        ])
1605                        .to_matchable(),
1606                        Sequence::new(vec![
1607                            Ref::keyword("RESET").to_matchable(),
1608                            one_of(vec![
1609                                Ref::keyword("ALL").to_matchable(),
1610                                Ref::new("ParameterNameSegment").to_matchable(),
1611                            ])
1612                            .to_matchable(),
1613                        ])
1614                        .to_matchable(),
1615                    ])
1616                    .to_matchable(),
1617                    Ref::keyword("RESTRICT").optional().to_matchable(),
1618                ])
1619                .to_matchable()
1620            })
1621            .to_matchable()
1622            .into(),
1623        ),
1624        (
1625            "AlterProcedureStatementSegment".into(),
1626            NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_| {
1627                Sequence::new(vec![
1628                    Ref::keyword("ALTER").to_matchable(),
1629                    Ref::keyword("PROCEDURE").to_matchable(),
1630                    Delimited::new(vec![
1631                        Sequence::new(vec![
1632                            Ref::new("FunctionNameSegment").to_matchable(),
1633                            Ref::new("FunctionParameterListGrammar")
1634                                .optional()
1635                                .to_matchable(),
1636                        ])
1637                        .to_matchable(),
1638                    ])
1639                    .to_matchable(),
1640                    one_of(vec![
1641                        Ref::new("AlterProcedureActionSegment")
1642                            .optional()
1643                            .to_matchable(),
1644                        Sequence::new(vec![
1645                            Ref::keyword("RENAME").to_matchable(),
1646                            Ref::keyword("TO").to_matchable(),
1647                            Ref::new("FunctionNameSegment").to_matchable(),
1648                        ])
1649                        .to_matchable(),
1650                        Sequence::new(vec![
1651                            Ref::keyword("SET").to_matchable(),
1652                            Ref::keyword("SCHEMA").to_matchable(),
1653                            Ref::new("SchemaReferenceSegment").to_matchable(),
1654                        ])
1655                        .to_matchable(),
1656                        Sequence::new(vec![
1657                            Ref::keyword("SET").to_matchable(),
1658                            Ref::new("ParameterNameSegment").to_matchable(),
1659                            one_of(vec![
1660                                Sequence::new(vec![
1661                                    one_of(vec![
1662                                        Ref::keyword("TO").to_matchable(),
1663                                        Ref::new("EqualsSegment").to_matchable(),
1664                                    ])
1665                                    .to_matchable(),
1666                                    Delimited::new(vec![
1667                                        one_of(vec![
1668                                            Ref::new("ParameterNameSegment").to_matchable(),
1669                                            Ref::new("LiteralGrammar").to_matchable(),
1670                                        ])
1671                                        .to_matchable(),
1672                                    ])
1673                                    .to_matchable(),
1674                                ])
1675                                .to_matchable(),
1676                                Sequence::new(vec![
1677                                    Ref::keyword("FROM").to_matchable(),
1678                                    Ref::keyword("CURRENT").to_matchable(),
1679                                ])
1680                                .to_matchable(),
1681                            ])
1682                            .to_matchable(),
1683                        ])
1684                        .to_matchable(),
1685                        Sequence::new(vec![
1686                            Ref::keyword("OWNER").to_matchable(),
1687                            Ref::keyword("TO").to_matchable(),
1688                            one_of(vec![
1689                                one_of(vec![
1690                                    Ref::new("ParameterNameSegment").to_matchable(),
1691                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
1692                                ])
1693                                .to_matchable(),
1694                                Ref::keyword("CURRENT_ROLE").to_matchable(),
1695                                Ref::keyword("CURRENT_USER").to_matchable(),
1696                                Ref::keyword("SESSION_USER").to_matchable(),
1697                            ])
1698                            .to_matchable(),
1699                        ])
1700                        .to_matchable(),
1701                        Sequence::new(vec![
1702                            Ref::keyword("NO").optional().to_matchable(),
1703                            Ref::keyword("DEPENDS").to_matchable(),
1704                            Ref::keyword("ON").to_matchable(),
1705                            Ref::keyword("EXTENSION").to_matchable(),
1706                            Ref::new("ExtensionReferenceSegment").to_matchable(),
1707                        ])
1708                        .to_matchable(),
1709                    ])
1710                    .to_matchable(),
1711                ])
1712                .to_matchable()
1713            })
1714            .to_matchable()
1715            .into(),
1716        ),
1717        (
1718            "CreateProcedureStatementSegment".into(),
1719            NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| {
1720                Sequence::new(vec![
1721                    Ref::keyword("CREATE").to_matchable(),
1722                    Sequence::new(vec![
1723                        Ref::keyword("OR").to_matchable(),
1724                        Ref::keyword("REPLACE").to_matchable(),
1725                    ])
1726                    .config(|this| this.optional())
1727                    .to_matchable(),
1728                    Ref::keyword("PROCEDURE").to_matchable(),
1729                    Ref::new("FunctionNameSegment").to_matchable(),
1730                    Ref::new("FunctionParameterListGrammar").to_matchable(),
1731                    Ref::new("FunctionDefinitionGrammar").to_matchable(),
1732                ])
1733                .to_matchable()
1734            })
1735            .to_matchable()
1736            .into(),
1737        ),
1738        (
1739            "DropProcedureStatementSegment".into(),
1740            NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_| {
1741                Sequence::new(vec![
1742                    Ref::keyword("DROP").to_matchable(),
1743                    Ref::keyword("PROCEDURE").to_matchable(),
1744                    Ref::new("IfExistsGrammar").optional().to_matchable(),
1745                    Delimited::new(vec![
1746                        Sequence::new(vec![
1747                            Ref::new("FunctionNameSegment").to_matchable(),
1748                            Ref::new("FunctionParameterListGrammar")
1749                                .optional()
1750                                .to_matchable(),
1751                        ])
1752                        .to_matchable(),
1753                    ])
1754                    .to_matchable(),
1755                    one_of(vec![
1756                        Ref::keyword("CASCADE").to_matchable(),
1757                        Ref::keyword("RESTRICT").to_matchable(),
1758                    ])
1759                    .config(|this| this.optional())
1760                    .to_matchable(),
1761                ])
1762                .to_matchable()
1763            })
1764            .to_matchable()
1765            .into(),
1766        ),
1767        (
1768            "WellKnownTextGeometrySegment".into(),
1769            NodeMatcher::new(SyntaxKind::WktGeometryType, |_| {
1770                let geometry_type_keywords = POSTGRES_POSTGIS_DATATYPE_KEYWORDS
1771                    .iter()
1772                    .map(|(kw, _)| Ref::keyword(*kw).to_matchable())
1773                    .collect_vec();
1774
1775                let mut geometry_type_keywords0 = geometry_type_keywords.clone();
1776                geometry_type_keywords0.extend(
1777                    ["GEOMETRY", "GEOGRAPHY"]
1778                        .into_iter()
1779                        .map(|it| Ref::keyword(it).to_matchable()),
1780                );
1781
1782                one_of(vec![
1783                    Sequence::new(vec![
1784                        one_of(geometry_type_keywords.clone()).to_matchable(),
1785                        Bracketed::new(vec![
1786                            Delimited::new(vec![
1787                                optionally_bracketed(vec![
1788                                    Delimited::new(vec![
1789                                        Ref::new("SimpleGeometryGrammar").to_matchable(),
1790                                    ])
1791                                    .to_matchable(),
1792                                ])
1793                                .to_matchable(),
1794                                Bracketed::new(vec![
1795                                    Delimited::new(vec![
1796                                        Bracketed::new(vec![
1797                                            Delimited::new(vec![
1798                                                Ref::new("SimpleGeometryGrammar").to_matchable(),
1799                                            ])
1800                                            .to_matchable(),
1801                                        ])
1802                                        .to_matchable(),
1803                                    ])
1804                                    .to_matchable(),
1805                                ])
1806                                .to_matchable(),
1807                                Ref::new("WellKnownTextGeometrySegment").to_matchable(),
1808                            ])
1809                            .to_matchable(),
1810                        ])
1811                        .to_matchable(),
1812                    ])
1813                    .to_matchable(),
1814                    Sequence::new(vec![
1815                        one_of(vec![
1816                            Ref::keyword("GEOMETRY").to_matchable(),
1817                            Ref::keyword("GEOGRAPHY").to_matchable(),
1818                        ])
1819                        .to_matchable(),
1820                        Bracketed::new(vec![
1821                            Sequence::new(vec![
1822                                one_of(geometry_type_keywords0).to_matchable(),
1823                                Ref::new("CommaSegment").to_matchable(),
1824                                Ref::new("NumericLiteralSegment").to_matchable(),
1825                            ])
1826                            .to_matchable(),
1827                        ])
1828                        .to_matchable(),
1829                    ])
1830                    .to_matchable(),
1831                ])
1832                .to_matchable()
1833            })
1834            .to_matchable()
1835            .into(),
1836        ),
1837        (
1838            "SemiStructuredAccessorSegment".into(),
1839            NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| {
1840                Sequence::new(vec![
1841                    Ref::new("DotSegment").to_matchable(),
1842                    Ref::new("SingleIdentifierGrammar").to_matchable(),
1843                    Ref::new("ArrayAccessorSegment").optional().to_matchable(),
1844                    AnyNumberOf::new(vec![
1845                        Sequence::new(vec![
1846                            Ref::new("DotSegment").to_matchable(),
1847                            Ref::new("SingleIdentifierGrammar").to_matchable(),
1848                        ])
1849                        .to_matchable(),
1850                        Ref::new("ArrayAccessorSegment").optional().to_matchable(),
1851                    ])
1852                    .to_matchable(),
1853                ])
1854                .to_matchable()
1855            })
1856            .to_matchable()
1857            .into(),
1858        ),
1859    ]);
1860
1861    postgres.replace_grammar(
1862        "FunctionDefinitionGrammar",
1863        Sequence::new(vec![
1864            AnyNumberOf::new(vec![
1865                Ref::new("LanguageClauseSegment").to_matchable(),
1866                Sequence::new(vec![
1867                    Ref::keyword("TRANSFORM").to_matchable(),
1868                    Ref::keyword("FOR").to_matchable(),
1869                    Ref::keyword("TYPE").to_matchable(),
1870                    Ref::new("ParameterNameSegment").to_matchable(),
1871                ])
1872                .to_matchable(),
1873                Ref::keyword("WINDOW").to_matchable(),
1874                one_of(vec![
1875                    Ref::keyword("IMMUTABLE").to_matchable(),
1876                    Ref::keyword("STABLE").to_matchable(),
1877                    Ref::keyword("VOLATILE").to_matchable(),
1878                ])
1879                .to_matchable(),
1880                Sequence::new(vec![
1881                    Ref::keyword("NOT").optional().to_matchable(),
1882                    Ref::keyword("LEAKPROOF").to_matchable(),
1883                ])
1884                .to_matchable(),
1885                one_of(vec![
1886                    Sequence::new(vec![
1887                        Ref::keyword("CALLED").to_matchable(),
1888                        Ref::keyword("ON").to_matchable(),
1889                        Ref::keyword("NULL").to_matchable(),
1890                        Ref::keyword("INPUT").to_matchable(),
1891                    ])
1892                    .to_matchable(),
1893                    Sequence::new(vec![
1894                        Ref::keyword("RETURNS").to_matchable(),
1895                        Ref::keyword("NULL").to_matchable(),
1896                        Ref::keyword("ON").to_matchable(),
1897                        Ref::keyword("NULL").to_matchable(),
1898                        Ref::keyword("INPUT").to_matchable(),
1899                    ])
1900                    .to_matchable(),
1901                    Ref::keyword("STRICT").to_matchable(),
1902                ])
1903                .to_matchable(),
1904                Sequence::new(vec![
1905                    Ref::keyword("EXTERNAL").optional().to_matchable(),
1906                    Ref::keyword("SECURITY").to_matchable(),
1907                    one_of(vec![
1908                        Ref::keyword("INVOKER").to_matchable(),
1909                        Ref::keyword("DEFINER").to_matchable(),
1910                    ])
1911                    .to_matchable(),
1912                ])
1913                .to_matchable(),
1914                Sequence::new(vec![
1915                    Ref::keyword("PARALLEL").to_matchable(),
1916                    one_of(vec![
1917                        Ref::keyword("UNSAFE").to_matchable(),
1918                        Ref::keyword("RESTRICTED").to_matchable(),
1919                        Ref::keyword("SAFE").to_matchable(),
1920                    ])
1921                    .to_matchable(),
1922                ])
1923                .to_matchable(),
1924                Sequence::new(vec![
1925                    Ref::keyword("COST").to_matchable(),
1926                    Ref::new("NumericLiteralSegment").to_matchable(),
1927                ])
1928                .to_matchable(),
1929                Sequence::new(vec![
1930                    Ref::keyword("ROWS").to_matchable(),
1931                    Ref::new("NumericLiteralSegment").to_matchable(),
1932                ])
1933                .to_matchable(),
1934                Sequence::new(vec![
1935                    Ref::keyword("SUPPORT").to_matchable(),
1936                    Ref::new("ParameterNameSegment").to_matchable(),
1937                ])
1938                .to_matchable(),
1939                Sequence::new(vec![
1940                    Ref::keyword("SET").to_matchable(),
1941                    Ref::new("ParameterNameSegment").to_matchable(),
1942                    one_of(vec![
1943                        Sequence::new(vec![
1944                            one_of(vec![
1945                                Ref::keyword("TO").to_matchable(),
1946                                Ref::new("EqualsSegment").to_matchable(),
1947                            ])
1948                            .to_matchable(),
1949                            Delimited::new(vec![
1950                                one_of(vec![
1951                                    Ref::new("ParameterNameSegment").to_matchable(),
1952                                    Ref::new("LiteralGrammar").to_matchable(),
1953                                ])
1954                                .to_matchable(),
1955                            ])
1956                            .to_matchable(),
1957                        ])
1958                        .to_matchable(),
1959                        Sequence::new(vec![
1960                            Ref::keyword("FROM").to_matchable(),
1961                            Ref::keyword("CURRENT").to_matchable(),
1962                        ])
1963                        .to_matchable(),
1964                    ])
1965                    .to_matchable(),
1966                ])
1967                .to_matchable(),
1968                Sequence::new(vec![
1969                    Ref::keyword("AS").to_matchable(),
1970                    one_of(vec![
1971                        Ref::new("QuotedLiteralSegment").to_matchable(),
1972                        Sequence::new(vec![
1973                            Ref::new("QuotedLiteralSegment").to_matchable(),
1974                            Ref::new("CommaSegment").to_matchable(),
1975                            Ref::new("QuotedLiteralSegment").to_matchable(),
1976                        ])
1977                        .to_matchable(),
1978                    ])
1979                    .to_matchable(),
1980                ])
1981                .to_matchable(),
1982            ])
1983            .to_matchable(),
1984            Sequence::new(vec![
1985                Ref::keyword("WITH").to_matchable(),
1986                Bracketed::new(vec![
1987                    Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()])
1988                        .to_matchable(),
1989                ])
1990                .to_matchable(),
1991            ])
1992            .config(|this| this.optional())
1993            .to_matchable(),
1994        ])
1995        .to_matchable(),
1996    );
1997
1998    postgres.add([
1999        (
2000            "IntoClauseSegment".into(),
2001            NodeMatcher::new(SyntaxKind::IntoClause, |_| {
2002                Sequence::new(vec![
2003                    Ref::keyword("INTO").to_matchable(),
2004                    one_of(vec![
2005                        Ref::keyword("TEMPORARY").to_matchable(),
2006                        Ref::keyword("TEMP").to_matchable(),
2007                        Ref::keyword("UNLOGGED").to_matchable(),
2008                    ])
2009                    .config(|this| this.optional())
2010                    .to_matchable(),
2011                    Ref::keyword("TABLE").optional().to_matchable(),
2012                    Ref::new("TableReferenceSegment").to_matchable(),
2013                ])
2014                .to_matchable()
2015            })
2016            .to_matchable()
2017            .into(),
2018        ),
2019        (
2020            "ForClauseSegment".into(),
2021            NodeMatcher::new(SyntaxKind::ForClause, |_| {
2022                Sequence::new(vec![
2023                    Ref::keyword("FOR").to_matchable(),
2024                    one_of(vec![
2025                        Ref::keyword("UPDATE").to_matchable(),
2026                        Sequence::new(vec![
2027                            Ref::keyword("NO").to_matchable(),
2028                            Ref::keyword("KEY").to_matchable(),
2029                            Ref::keyword("UPDATE").to_matchable(),
2030                        ])
2031                        .to_matchable(),
2032                        Ref::keyword("SHARE").to_matchable(),
2033                        Sequence::new(vec![
2034                            Ref::keyword("KEY").to_matchable(),
2035                            Ref::keyword("SHARE").to_matchable(),
2036                        ])
2037                        .to_matchable(),
2038                    ])
2039                    .to_matchable(),
2040                    Sequence::new(vec![
2041                        Ref::keyword("OF").to_matchable(),
2042                        Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
2043                            .to_matchable(),
2044                    ])
2045                    .config(|this| this.optional())
2046                    .to_matchable(),
2047                    one_of(vec![
2048                        Ref::keyword("NOWAIT").to_matchable(),
2049                        Sequence::new(vec![
2050                            Ref::keyword("SKIP").to_matchable(),
2051                            Ref::keyword("LOCKED").to_matchable(),
2052                        ])
2053                        .to_matchable(),
2054                    ])
2055                    .config(|this| this.optional())
2056                    .to_matchable(),
2057                ])
2058                .to_matchable()
2059            })
2060            .to_matchable()
2061            .into(),
2062        ),
2063    ]);
2064
2065    postgres.replace_grammar(
2066        "UnorderedSelectStatementSegment",
2067        ansi::get_unordered_select_statement_segment_grammar().copy(
2068            Some(vec![
2069                Ref::new("IntoClauseSegment").optional().to_matchable(),
2070            ]),
2071            None,
2072            Some(Ref::new("FromClauseSegment").optional().to_matchable()),
2073            None,
2074            vec![
2075                Sequence::new(vec![
2076                    Ref::keyword("WITH").to_matchable(),
2077                    Ref::keyword("NO").optional().to_matchable(),
2078                    Ref::keyword("DATA").to_matchable(),
2079                ])
2080                .to_matchable(),
2081                Sequence::new(vec![
2082                    Ref::keyword("ON").to_matchable(),
2083                    Ref::keyword("CONFLICT").to_matchable(),
2084                ])
2085                .to_matchable(),
2086                Ref::keyword("RETURNING").to_matchable(),
2087                Ref::new("WithCheckOptionSegment").to_matchable(),
2088            ],
2089            false,
2090        ),
2091    );
2092
2093    postgres.replace_grammar(
2094        "SelectStatementSegment",
2095        postgres
2096            .grammar("UnorderedSelectStatementSegment")
2097            .match_grammar(&postgres)
2098            .unwrap()
2099            .copy(
2100                Some(vec![
2101                    Ref::new("OrderByClauseSegment").optional().to_matchable(),
2102                    Ref::new("LimitClauseSegment").optional().to_matchable(),
2103                    Ref::new("NamedWindowSegment").optional().to_matchable(),
2104                ]),
2105                None,
2106                None,
2107                None,
2108                vec![],
2109                false,
2110            )
2111            .copy(
2112                Some(vec![Ref::new("ForClauseSegment").optional().to_matchable()]),
2113                None,
2114                Some(Ref::new("LimitClauseSegment").optional().to_matchable()),
2115                None,
2116                vec![
2117                    Ref::new("SetOperatorSegment").to_matchable(),
2118                    Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
2119                    Ref::new("WithDataClauseSegment").to_matchable(),
2120                    Sequence::new(vec![
2121                        Ref::keyword("ON").to_matchable(),
2122                        Ref::keyword("CONFLICT").to_matchable(),
2123                    ])
2124                    .to_matchable(),
2125                    Ref::keyword("RETURNING").to_matchable(),
2126                    Ref::new("WithCheckOptionSegment").to_matchable(),
2127                ],
2128                true,
2129            ),
2130    );
2131
2132    postgres.replace_grammar(
2133        "SelectClauseSegment",
2134        Sequence::new(vec![
2135            Ref::keyword("SELECT").to_matchable(),
2136            Ref::new("SelectClauseModifierSegment")
2137                .optional()
2138                .to_matchable(),
2139            MetaSegment::indent().to_matchable(),
2140            Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()])
2141                .config(|this| {
2142                    this.optional();
2143                    this.allow_trailing = true;
2144                })
2145                .to_matchable(),
2146        ])
2147        .config(|this| {
2148            this.terminators = vec![
2149                Ref::keyword("INTO").to_matchable(),
2150                Ref::keyword("FROM").to_matchable(),
2151                Ref::keyword("WHERE").to_matchable(),
2152                Sequence::new(vec![
2153                    Ref::keyword("ORDER").to_matchable(),
2154                    Ref::keyword("BY").to_matchable(),
2155                ])
2156                .to_matchable(),
2157                Ref::keyword("LIMIT").to_matchable(),
2158                Ref::keyword("OVERLAPS").to_matchable(),
2159                Ref::new("SetOperatorSegment").to_matchable(),
2160                Sequence::new(vec![
2161                    Ref::keyword("WITH").to_matchable(),
2162                    Ref::keyword("NO").optional().to_matchable(),
2163                    Ref::keyword("DATA").to_matchable(),
2164                ])
2165                .to_matchable(),
2166                Ref::new("WithCheckOptionSegment").to_matchable(),
2167            ];
2168            this.parse_mode(ParseMode::GreedyOnceStarted);
2169        })
2170        .to_matchable(),
2171    );
2172
2173    postgres.replace_grammar(
2174        "SelectClauseModifierSegment",
2175        one_of(vec![
2176            Sequence::new(vec![
2177                Ref::keyword("DISTINCT").to_matchable(),
2178                Sequence::new(vec![
2179                    Ref::keyword("ON").to_matchable(),
2180                    Bracketed::new(vec![
2181                        Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
2182                            .to_matchable(),
2183                    ])
2184                    .config(|this| this.optional())
2185                    .to_matchable(),
2186                ])
2187                .config(|this| this.optional())
2188                .to_matchable(),
2189            ])
2190            .to_matchable(),
2191            Ref::keyword("ALL").to_matchable(),
2192        ])
2193        .to_matchable(),
2194    );
2195
2196    postgres.add([
2197        (
2198            "WithinGroupClauseSegment".into(),
2199            NodeMatcher::new(SyntaxKind::WithingroupClause, |_| {
2200                Sequence::new(vec![
2201                    Ref::keyword("WITHIN").to_matchable(),
2202                    Ref::keyword("GROUP").to_matchable(),
2203                    Bracketed::new(vec![
2204                        Ref::new("OrderByClauseSegment").optional().to_matchable(),
2205                    ])
2206                    .to_matchable(),
2207                ])
2208                .to_matchable()
2209            })
2210            .to_matchable()
2211            .into(),
2212        ),
2213        (
2214            "GroupByClauseSegment".into(),
2215            NodeMatcher::new(SyntaxKind::GroupbyClause, |_| {
2216                Sequence::new(vec![
2217                    Ref::keyword("GROUP").to_matchable(),
2218                    Ref::keyword("BY").to_matchable(),
2219                    MetaSegment::indent().to_matchable(),
2220                    Delimited::new(vec![
2221                        one_of(vec![
2222                            Ref::new("ColumnReferenceSegment").to_matchable(),
2223                            Ref::new("NumericLiteralSegment").to_matchable(),
2224                            Ref::new("CubeRollupClauseSegment").to_matchable(),
2225                            Ref::new("GroupingSetsClauseSegment").to_matchable(),
2226                            Ref::new("ExpressionSegment").to_matchable(),
2227                            Bracketed::new(vec![]).to_matchable(),
2228                        ])
2229                        .to_matchable(),
2230                    ])
2231                    .config(|this| {
2232                        this.terminators = vec![
2233                            Sequence::new(vec![
2234                                Ref::keyword("ORDER").to_matchable(),
2235                                Ref::keyword("BY").to_matchable(),
2236                            ])
2237                            .to_matchable(),
2238                            Ref::keyword("LIMIT").to_matchable(),
2239                            Ref::keyword("HAVING").to_matchable(),
2240                            Ref::keyword("QUALIFY").to_matchable(),
2241                            Ref::keyword("WINDOW").to_matchable(),
2242                            Ref::new("SetOperatorSegment").to_matchable(),
2243                        ];
2244                    })
2245                    .to_matchable(),
2246                    MetaSegment::dedent().to_matchable(),
2247                ])
2248                .to_matchable()
2249            })
2250            .to_matchable()
2251            .into(),
2252        ),
2253    ]);
2254
2255    postgres.replace_grammar(
2256        "CreateRoleStatementSegment",
2257        Sequence::new(vec![
2258            Ref::keyword("CREATE").to_matchable(),
2259            one_of(vec![
2260                Ref::keyword("ROLE").to_matchable(),
2261                Ref::keyword("USER").to_matchable(),
2262            ])
2263            .to_matchable(),
2264            Ref::new("RoleReferenceSegment").to_matchable(),
2265            Sequence::new(vec![
2266                Ref::keyword("WITH").optional().to_matchable(),
2267                any_set_of(vec![
2268                    one_of(vec![
2269                        Ref::keyword("SUPERUSER").to_matchable(),
2270                        Ref::keyword("NOSUPERUSER").to_matchable(),
2271                    ])
2272                    .to_matchable(),
2273                    one_of(vec![
2274                        Ref::keyword("CREATEDB").to_matchable(),
2275                        Ref::keyword("NOCREATEDB").to_matchable(),
2276                    ])
2277                    .to_matchable(),
2278                    one_of(vec![
2279                        Ref::keyword("CREATEROLE").to_matchable(),
2280                        Ref::keyword("NOCREATEROLE").to_matchable(),
2281                    ])
2282                    .to_matchable(),
2283                    one_of(vec![
2284                        Ref::keyword("INHERIT").to_matchable(),
2285                        Ref::keyword("NOINHERIT").to_matchable(),
2286                    ])
2287                    .to_matchable(),
2288                    one_of(vec![
2289                        Ref::keyword("LOGIN").to_matchable(),
2290                        Ref::keyword("NOLOGIN").to_matchable(),
2291                    ])
2292                    .to_matchable(),
2293                    one_of(vec![
2294                        Ref::keyword("REPLICATION").to_matchable(),
2295                        Ref::keyword("NOREPLICATION").to_matchable(),
2296                    ])
2297                    .to_matchable(),
2298                    one_of(vec![
2299                        Ref::keyword("BYPASSRLS").to_matchable(),
2300                        Ref::keyword("NOBYPASSRLS").to_matchable(),
2301                    ])
2302                    .to_matchable(),
2303                    Sequence::new(vec![
2304                        Ref::keyword("CONNECTION").to_matchable(),
2305                        Ref::keyword("LIMIT").to_matchable(),
2306                        Ref::new("NumericLiteralSegment").to_matchable(),
2307                    ])
2308                    .to_matchable(),
2309                    Sequence::new(vec![
2310                        Ref::keyword("PASSWORD").to_matchable(),
2311                        one_of(vec![
2312                            Ref::new("QuotedLiteralSegment").to_matchable(),
2313                            Ref::keyword("NULL").to_matchable(),
2314                        ])
2315                        .to_matchable(),
2316                    ])
2317                    .to_matchable(),
2318                    Sequence::new(vec![
2319                        Ref::keyword("VALID").to_matchable(),
2320                        Ref::keyword("UNTIL").to_matchable(),
2321                        Ref::new("QuotedLiteralSegment").to_matchable(),
2322                    ])
2323                    .to_matchable(),
2324                    Sequence::new(vec![
2325                        Ref::keyword("IN").to_matchable(),
2326                        Ref::keyword("ROLE").to_matchable(),
2327                        Ref::new("RoleReferenceSegment").to_matchable(),
2328                    ])
2329                    .to_matchable(),
2330                    Sequence::new(vec![
2331                        Ref::keyword("IN").to_matchable(),
2332                        Ref::keyword("GROUP").to_matchable(),
2333                        Ref::new("RoleReferenceSegment").to_matchable(),
2334                    ])
2335                    .to_matchable(),
2336                    Sequence::new(vec![
2337                        Ref::keyword("ROLE").to_matchable(),
2338                        Ref::new("RoleReferenceSegment").to_matchable(),
2339                    ])
2340                    .to_matchable(),
2341                    Sequence::new(vec![
2342                        Ref::keyword("ADMIN").to_matchable(),
2343                        Ref::new("RoleReferenceSegment").to_matchable(),
2344                    ])
2345                    .to_matchable(),
2346                    Sequence::new(vec![
2347                        Ref::keyword("USER").to_matchable(),
2348                        Ref::new("RoleReferenceSegment").to_matchable(),
2349                    ])
2350                    .to_matchable(),
2351                    Sequence::new(vec![
2352                        Ref::keyword("SYSID").to_matchable(),
2353                        Ref::new("NumericLiteralSegment").to_matchable(),
2354                    ])
2355                    .to_matchable(),
2356                ])
2357                .config(|this| this.optional())
2358                .to_matchable(),
2359            ])
2360            .config(|this| this.optional())
2361            .to_matchable(),
2362        ])
2363        .to_matchable(),
2364    );
2365
2366    postgres.add([(
2367        "AlterRoleStatementSegment".into(),
2368        NodeMatcher::new(SyntaxKind::AlterRoleStatement, |_| {
2369            Sequence::new(vec![
2370                Ref::keyword("ALTER").to_matchable(),
2371                one_of(vec![
2372                    Ref::keyword("ROLE").to_matchable(),
2373                    Ref::keyword("USER").to_matchable(),
2374                ])
2375                .to_matchable(),
2376                one_of(vec![
2377                    // role_specification
2378                    Sequence::new(vec![
2379                        one_of(vec![
2380                            Ref::keyword("CURRENT_ROLE").to_matchable(),
2381                            Ref::keyword("CURRENT_USER").to_matchable(),
2382                            Ref::keyword("SESSION_USER").to_matchable(),
2383                            Ref::new("RoleReferenceSegment").to_matchable(),
2384                        ])
2385                        .to_matchable(),
2386                        Ref::keyword("WITH").optional().to_matchable(),
2387                        any_set_of(vec![
2388                            one_of(vec![
2389                                Ref::keyword("SUPERUSER").to_matchable(),
2390                                Ref::keyword("NOSUPERUSER").to_matchable(),
2391                            ])
2392                            .to_matchable(),
2393                            one_of(vec![
2394                                Ref::keyword("CREATEDB").to_matchable(),
2395                                Ref::keyword("NOCREATEDB").to_matchable(),
2396                            ])
2397                            .to_matchable(),
2398                            one_of(vec![
2399                                Ref::keyword("CREATEROLE").to_matchable(),
2400                                Ref::keyword("NOCREATEROLE").to_matchable(),
2401                            ])
2402                            .to_matchable(),
2403                            one_of(vec![
2404                                Ref::keyword("INHERIT").to_matchable(),
2405                                Ref::keyword("NOINHERIT").to_matchable(),
2406                            ])
2407                            .to_matchable(),
2408                            one_of(vec![
2409                                Ref::keyword("LOGIN").to_matchable(),
2410                                Ref::keyword("NOLOGIN").to_matchable(),
2411                            ])
2412                            .to_matchable(),
2413                            one_of(vec![
2414                                Ref::keyword("REPLICATION").to_matchable(),
2415                                Ref::keyword("NOREPLICATION").to_matchable(),
2416                            ])
2417                            .to_matchable(),
2418                            one_of(vec![
2419                                Ref::keyword("BYPASSRLS").to_matchable(),
2420                                Ref::keyword("NOBYPASSRLS").to_matchable(),
2421                            ])
2422                            .to_matchable(),
2423                            Sequence::new(vec![
2424                                Ref::keyword("CONNECTION").to_matchable(),
2425                                Ref::keyword("LIMIT").to_matchable(),
2426                                Ref::new("NumericLiteralSegment").to_matchable(),
2427                            ])
2428                            .to_matchable(),
2429                            Sequence::new(vec![
2430                                Ref::keyword("ENCRYPTED").optional().to_matchable(),
2431                                Ref::keyword("PASSWORD").to_matchable(),
2432                                one_of(vec![
2433                                    Ref::new("QuotedLiteralSegment").to_matchable(),
2434                                    Ref::keyword("NULL").to_matchable(),
2435                                ])
2436                                .to_matchable(),
2437                            ])
2438                            .to_matchable(),
2439                            Sequence::new(vec![
2440                                Ref::keyword("VALID").to_matchable(),
2441                                Ref::keyword("UNTIL").to_matchable(),
2442                                Ref::new("QuotedLiteralSegment").to_matchable(),
2443                            ])
2444                            .to_matchable(),
2445                        ])
2446                        .to_matchable(),
2447                    ])
2448                    .to_matchable(),
2449                    // name only
2450                    Sequence::new(vec![
2451                        Ref::new("RoleReferenceSegment").to_matchable(),
2452                        Sequence::new(vec![
2453                            Ref::keyword("RENAME").to_matchable(),
2454                            Ref::keyword("TO").to_matchable(),
2455                            Ref::new("RoleReferenceSegment").to_matchable(),
2456                        ])
2457                        .to_matchable(),
2458                    ])
2459                    .to_matchable(),
2460                    // role_specification | all
2461                    Sequence::new(vec![
2462                        one_of(vec![
2463                            Ref::keyword("CURRENT_ROLE").to_matchable(),
2464                            Ref::keyword("CURRENT_USER").to_matchable(),
2465                            Ref::keyword("SESSION_USER").to_matchable(),
2466                            Ref::keyword("ALL").to_matchable(),
2467                            Ref::new("RoleReferenceSegment").to_matchable(),
2468                        ])
2469                        .to_matchable(),
2470                        Sequence::new(vec![
2471                            Ref::keyword("IN").to_matchable(),
2472                            Ref::keyword("DATABASE").to_matchable(),
2473                            Ref::new("DatabaseReferenceSegment").to_matchable(),
2474                        ])
2475                        .config(|this| this.optional())
2476                        .to_matchable(),
2477                        one_of(vec![
2478                            Sequence::new(vec![
2479                                Ref::keyword("SET").to_matchable(),
2480                                Ref::new("ParameterNameSegment").to_matchable(),
2481                                one_of(vec![
2482                                    Sequence::new(vec![
2483                                        one_of(vec![
2484                                            Ref::keyword("TO").to_matchable(),
2485                                            Ref::new("EqualsSegment").to_matchable(),
2486                                        ])
2487                                        .to_matchable(),
2488                                        one_of(vec![
2489                                            Ref::keyword("DEFAULT").to_matchable(),
2490                                            Delimited::new(vec![
2491                                                Ref::new("LiteralGrammar").to_matchable(),
2492                                                Ref::new("NakedIdentifierSegment").to_matchable(),
2493                                                Ref::new("OnKeywordAsIdentifierSegment")
2494                                                    .to_matchable(),
2495                                            ])
2496                                            .to_matchable(),
2497                                        ])
2498                                        .to_matchable(),
2499                                    ])
2500                                    .to_matchable(),
2501                                    Sequence::new(vec![
2502                                        Ref::keyword("FROM").to_matchable(),
2503                                        Ref::keyword("CURRENT").to_matchable(),
2504                                    ])
2505                                    .to_matchable(),
2506                                ])
2507                                .to_matchable(),
2508                            ])
2509                            .to_matchable(),
2510                            Sequence::new(vec![
2511                                Ref::keyword("RESET").to_matchable(),
2512                                one_of(vec![
2513                                    Ref::new("ParameterNameSegment").to_matchable(),
2514                                    Ref::keyword("ALL").to_matchable(),
2515                                ])
2516                                .to_matchable(),
2517                            ])
2518                            .to_matchable(),
2519                        ])
2520                        .to_matchable(),
2521                    ])
2522                    .to_matchable(),
2523                ])
2524                .to_matchable(),
2525            ])
2526            .to_matchable()
2527        })
2528        .to_matchable()
2529        .into(),
2530    )]);
2531
2532    postgres.replace_grammar(
2533        "ExplainStatementSegment",
2534        Sequence::new(vec![
2535            Ref::keyword("EXPLAIN").to_matchable(),
2536            one_of(vec![
2537                Sequence::new(vec![
2538                    one_of(vec![
2539                        Ref::keyword("ANALYZE").optional().to_matchable(),
2540                        Ref::keyword("ANALYSE").optional().to_matchable(),
2541                    ])
2542                    .to_matchable(),
2543                    Ref::keyword("VERBOSE").optional().to_matchable(),
2544                ])
2545                .to_matchable(),
2546                Bracketed::new(vec![
2547                    Delimited::new(vec![Ref::new("ExplainOptionSegment").to_matchable()])
2548                        .to_matchable(),
2549                ])
2550                .to_matchable(),
2551            ])
2552            .config(|this| this.optional())
2553            .to_matchable(),
2554            ansi::explainable_stmt().to_matchable(),
2555        ])
2556        .to_matchable(),
2557    );
2558
2559    postgres.add([(
2560        "ExplainOptionSegment".into(),
2561        NodeMatcher::new(SyntaxKind::ExplainOption, |_| {
2562            one_of(vec![
2563                Sequence::new(vec![
2564                    one_of(vec![
2565                        Ref::keyword("ANALYZE").to_matchable(),
2566                        Ref::keyword("ANALYSE").to_matchable(),
2567                        Ref::keyword("VERBOSE").to_matchable(),
2568                        Ref::keyword("COSTS").to_matchable(),
2569                        Ref::keyword("SETTINGS").to_matchable(),
2570                        Ref::keyword("BUFFERS").to_matchable(),
2571                        Ref::keyword("WAL").to_matchable(),
2572                        Ref::keyword("TIMING").to_matchable(),
2573                        Ref::keyword("SUMMARY").to_matchable(),
2574                    ])
2575                    .to_matchable(),
2576                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
2577                ])
2578                .to_matchable(),
2579                Sequence::new(vec![
2580                    Ref::keyword("FORMAT").to_matchable(),
2581                    one_of(vec![
2582                        Ref::keyword("TEXT").to_matchable(),
2583                        Ref::keyword("XML").to_matchable(),
2584                        Ref::keyword("JSON").to_matchable(),
2585                        Ref::keyword("YAML").to_matchable(),
2586                    ])
2587                    .to_matchable(),
2588                ])
2589                .to_matchable(),
2590            ])
2591            .to_matchable()
2592        })
2593        .to_matchable()
2594        .into(),
2595    )]);
2596
2597    postgres.replace_grammar(
2598        "CreateSchemaStatementSegment",
2599        Sequence::new(vec![
2600            Ref::keyword("CREATE").to_matchable(),
2601            Ref::keyword("SCHEMA").to_matchable(),
2602            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2603            one_of(vec![
2604                Sequence::new(vec![
2605                    Ref::new("SchemaReferenceSegment").optional().to_matchable(),
2606                    Ref::keyword("AUTHORIZATION").to_matchable(),
2607                    Ref::new("RoleReferenceSegment").to_matchable(),
2608                ])
2609                .to_matchable(),
2610                Ref::new("SchemaReferenceSegment").to_matchable(),
2611            ])
2612            .to_matchable(),
2613        ])
2614        .to_matchable(),
2615    );
2616
2617    postgres.replace_grammar(
2618        "CreateTableStatementSegment",
2619        Sequence::new(vec![
2620            Ref::keyword("CREATE").to_matchable(),
2621            one_of(vec![
2622                Sequence::new(vec![
2623                    one_of(vec![
2624                        Ref::keyword("GLOBAL").to_matchable(),
2625                        Ref::keyword("LOCAL").to_matchable(),
2626                    ])
2627                    .config(|this| this.optional())
2628                    .to_matchable(),
2629                    Ref::new("TemporaryGrammar").optional().to_matchable(),
2630                ])
2631                .to_matchable(),
2632                Ref::keyword("UNLOGGED").to_matchable(),
2633            ])
2634            .config(|this| this.optional())
2635            .to_matchable(),
2636            Ref::keyword("TABLE").to_matchable(),
2637            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2638            Ref::new("TableReferenceSegment").to_matchable(),
2639            one_of(vec![
2640                Sequence::new(vec![
2641                    Bracketed::new(vec![
2642                        Delimited::new(vec![
2643                            one_of(vec![
2644                                Sequence::new(vec![
2645                                    Ref::new("ColumnReferenceSegment").to_matchable(),
2646                                    Ref::new("DatatypeSegment").to_matchable(),
2647                                    AnyNumberOf::new(vec![
2648                                        one_of(vec![
2649                                            Ref::new("ColumnConstraintSegment").to_matchable(),
2650                                            Sequence::new(vec![
2651                                                Ref::keyword("COLLATE").to_matchable(),
2652                                                Ref::new("CollationReferenceSegment")
2653                                                    .to_matchable(),
2654                                            ])
2655                                            .to_matchable(),
2656                                        ])
2657                                        .to_matchable(),
2658                                    ])
2659                                    .to_matchable(),
2660                                ])
2661                                .to_matchable(),
2662                                Ref::new("TableConstraintSegment").to_matchable(),
2663                                Sequence::new(vec![
2664                                    Ref::keyword("LIKE").to_matchable(),
2665                                    Ref::new("TableReferenceSegment").to_matchable(),
2666                                    AnyNumberOf::new(vec![
2667                                        Ref::new("LikeOptionSegment").to_matchable(),
2668                                    ])
2669                                    .config(|this| this.optional())
2670                                    .to_matchable(),
2671                                ])
2672                                .to_matchable(),
2673                            ])
2674                            .to_matchable(),
2675                        ])
2676                        .config(|this| this.optional())
2677                        .to_matchable(),
2678                    ])
2679                    .to_matchable(),
2680                    Sequence::new(vec![
2681                        Ref::keyword("INHERITS").to_matchable(),
2682                        Bracketed::new(vec![
2683                            Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
2684                                .to_matchable(),
2685                        ])
2686                        .to_matchable(),
2687                    ])
2688                    .config(|this| this.optional())
2689                    .to_matchable(),
2690                ])
2691                .to_matchable(),
2692                Sequence::new(vec![
2693                    Ref::keyword("OF").to_matchable(),
2694                    Ref::new("ParameterNameSegment").to_matchable(),
2695                    Bracketed::new(vec![
2696                        Delimited::new(vec![
2697                            Sequence::new(vec![
2698                                Ref::new("ColumnReferenceSegment").to_matchable(),
2699                                Sequence::new(vec![
2700                                    Ref::keyword("WITH").to_matchable(),
2701                                    Ref::keyword("OPTIONS").to_matchable(),
2702                                ])
2703                                .config(|this| this.optional())
2704                                .to_matchable(),
2705                                AnyNumberOf::new(vec![
2706                                    Ref::new("ColumnConstraintSegment").to_matchable(),
2707                                ])
2708                                .to_matchable(),
2709                            ])
2710                            .to_matchable(),
2711                            Ref::new("TableConstraintSegment").to_matchable(),
2712                        ])
2713                        .config(|this| this.optional())
2714                        .to_matchable(),
2715                    ])
2716                    .to_matchable(),
2717                ])
2718                .to_matchable(),
2719                Sequence::new(vec![
2720                    Ref::keyword("PARTITION").to_matchable(),
2721                    Ref::keyword("OF").to_matchable(),
2722                    Ref::new("TableReferenceSegment").to_matchable(),
2723                    Bracketed::new(vec![
2724                        Delimited::new(vec![
2725                            Sequence::new(vec![
2726                                Ref::new("ColumnReferenceSegment").to_matchable(),
2727                                Sequence::new(vec![
2728                                    Ref::keyword("WITH").to_matchable(),
2729                                    Ref::keyword("OPTIONS").to_matchable(),
2730                                ])
2731                                .config(|this| this.optional())
2732                                .to_matchable(),
2733                                AnyNumberOf::new(vec![
2734                                    Ref::new("ColumnConstraintSegment").to_matchable(),
2735                                ])
2736                                .to_matchable(),
2737                            ])
2738                            .to_matchable(),
2739                            Ref::new("TableConstraintSegment").to_matchable(),
2740                        ])
2741                        .to_matchable(),
2742                    ])
2743                    .config(|this| this.optional())
2744                    .to_matchable(),
2745                    one_of(vec![
2746                        Sequence::new(vec![
2747                            Ref::keyword("FOR").to_matchable(),
2748                            Ref::keyword("VALUES").to_matchable(),
2749                            Ref::new("PartitionBoundSpecSegment").to_matchable(),
2750                        ])
2751                        .to_matchable(),
2752                        Ref::keyword("DEFAULT").to_matchable(),
2753                    ])
2754                    .to_matchable(),
2755                ])
2756                .to_matchable(),
2757            ])
2758            .to_matchable(),
2759            AnyNumberOf::new(vec![
2760                Sequence::new(vec![
2761                    Ref::keyword("PARTITION").to_matchable(),
2762                    Ref::keyword("BY").to_matchable(),
2763                    one_of(vec![
2764                        Ref::keyword("RANGE").to_matchable(),
2765                        Ref::keyword("LIST").to_matchable(),
2766                        Ref::keyword("HASH").to_matchable(),
2767                    ])
2768                    .to_matchable(),
2769                    Bracketed::new(vec![
2770                        AnyNumberOf::new(vec![
2771                            Delimited::new(vec![
2772                                Sequence::new(vec![
2773                                    one_of(vec![
2774                                        Ref::new("ColumnReferenceSegment").to_matchable(),
2775                                        Ref::new("FunctionSegment").to_matchable(),
2776                                    ])
2777                                    .to_matchable(),
2778                                    AnyNumberOf::new(vec![
2779                                        Sequence::new(vec![
2780                                            Ref::keyword("COLLATE").to_matchable(),
2781                                            Ref::new("CollationReferenceSegment").to_matchable(),
2782                                        ])
2783                                        .config(|this| this.optional())
2784                                        .to_matchable(),
2785                                        Ref::new("ParameterNameSegment").optional().to_matchable(),
2786                                    ])
2787                                    .to_matchable(),
2788                                ])
2789                                .to_matchable(),
2790                            ])
2791                            .to_matchable(),
2792                        ])
2793                        .to_matchable(),
2794                    ])
2795                    .to_matchable(),
2796                ])
2797                .to_matchable(),
2798                Sequence::new(vec![
2799                    Ref::keyword("USING").to_matchable(),
2800                    Ref::new("ParameterNameSegment").to_matchable(),
2801                ])
2802                .to_matchable(),
2803                one_of(vec![
2804                    Sequence::new(vec![
2805                        Ref::keyword("WITH").to_matchable(),
2806                        Ref::new("RelationOptionsSegment").to_matchable(),
2807                    ])
2808                    .to_matchable(),
2809                    Sequence::new(vec![
2810                        Ref::keyword("WITHOUT").to_matchable(),
2811                        Ref::keyword("OIDS").to_matchable(),
2812                    ])
2813                    .to_matchable(),
2814                ])
2815                .to_matchable(),
2816                Sequence::new(vec![
2817                    Ref::keyword("ON").to_matchable(),
2818                    Ref::keyword("COMMIT").to_matchable(),
2819                    one_of(vec![
2820                        Sequence::new(vec![
2821                            Ref::keyword("PRESERVE").to_matchable(),
2822                            Ref::keyword("ROWS").to_matchable(),
2823                        ])
2824                        .to_matchable(),
2825                        Sequence::new(vec![
2826                            Ref::keyword("DELETE").to_matchable(),
2827                            Ref::keyword("ROWS").to_matchable(),
2828                        ])
2829                        .to_matchable(),
2830                        Ref::keyword("DROP").to_matchable(),
2831                    ])
2832                    .to_matchable(),
2833                ])
2834                .to_matchable(),
2835                Sequence::new(vec![
2836                    Ref::keyword("TABLESPACE").to_matchable(),
2837                    Ref::new("TablespaceReferenceSegment").to_matchable(),
2838                ])
2839                .to_matchable(),
2840            ])
2841            .to_matchable(),
2842        ])
2843        .to_matchable(),
2844    );
2845
2846    postgres.add([(
2847        "CreateTableAsStatementSegment".into(),
2848        NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_| {
2849            Sequence::new(vec![
2850                Ref::keyword("CREATE").to_matchable(),
2851                one_of(vec![
2852                    Sequence::new(vec![
2853                        one_of(vec![
2854                            Ref::keyword("GLOBAL").to_matchable(),
2855                            Ref::keyword("LOCAL").to_matchable(),
2856                        ])
2857                        .config(|this| this.optional())
2858                        .to_matchable(),
2859                        Ref::new("TemporaryGrammar").to_matchable(),
2860                    ])
2861                    .to_matchable(),
2862                    Ref::keyword("UNLOGGED").to_matchable(),
2863                ])
2864                .config(|this| this.optional())
2865                .to_matchable(),
2866                Ref::keyword("TABLE").to_matchable(),
2867                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2868                Ref::new("TableReferenceSegment").to_matchable(),
2869                AnyNumberOf::new(vec![
2870                    Sequence::new(vec![
2871                        Bracketed::new(vec![
2872                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
2873                                .to_matchable(),
2874                        ])
2875                        .to_matchable(),
2876                    ])
2877                    .config(|this| this.optional())
2878                    .to_matchable(),
2879                    Sequence::new(vec![
2880                        Ref::keyword("USING").to_matchable(),
2881                        Ref::new("ParameterNameSegment").to_matchable(),
2882                    ])
2883                    .config(|this| this.optional())
2884                    .to_matchable(),
2885                    one_of(vec![
2886                        Sequence::new(vec![
2887                            Ref::keyword("WITH").to_matchable(),
2888                            Bracketed::new(vec![
2889                                Delimited::new(vec![
2890                                    Sequence::new(vec![
2891                                        Ref::new("ParameterNameSegment").to_matchable(),
2892                                        Sequence::new(vec![
2893                                            Ref::new("EqualsSegment").to_matchable(),
2894                                            one_of(vec![
2895                                                Ref::new("LiteralGrammar").to_matchable(),
2896                                                Ref::new("NakedIdentifierSegment").to_matchable(),
2897                                            ])
2898                                            .to_matchable(),
2899                                        ])
2900                                        .config(|this| this.optional())
2901                                        .to_matchable(),
2902                                    ])
2903                                    .to_matchable(),
2904                                ])
2905                                .to_matchable(),
2906                            ])
2907                            .to_matchable(),
2908                        ])
2909                        .to_matchable(),
2910                        Sequence::new(vec![
2911                            Ref::keyword("WITHOUT").to_matchable(),
2912                            Ref::keyword("OIDS").to_matchable(),
2913                        ])
2914                        .to_matchable(),
2915                    ])
2916                    .config(|this| this.optional())
2917                    .to_matchable(),
2918                    Sequence::new(vec![
2919                        Ref::keyword("ON").to_matchable(),
2920                        Ref::keyword("COMMIT").to_matchable(),
2921                        one_of(vec![
2922                            Sequence::new(vec![
2923                                Ref::keyword("PRESERVE").to_matchable(),
2924                                Ref::keyword("ROWS").to_matchable(),
2925                            ])
2926                            .to_matchable(),
2927                            Sequence::new(vec![
2928                                Ref::keyword("DELETE").to_matchable(),
2929                                Ref::keyword("ROWS").to_matchable(),
2930                            ])
2931                            .to_matchable(),
2932                            Ref::keyword("DROP").to_matchable(),
2933                        ])
2934                        .to_matchable(),
2935                    ])
2936                    .config(|this| this.optional())
2937                    .to_matchable(),
2938                    Sequence::new(vec![
2939                        Ref::keyword("TABLESPACE").to_matchable(),
2940                        Ref::new("TablespaceReferenceSegment").to_matchable(),
2941                    ])
2942                    .config(|this| this.optional())
2943                    .to_matchable(),
2944                ])
2945                .to_matchable(),
2946                Ref::keyword("AS").to_matchable(),
2947                one_of(vec![
2948                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
2949                        .to_matchable(),
2950                    optionally_bracketed(vec![
2951                        Sequence::new(vec![
2952                            Ref::keyword("TABLE").to_matchable(),
2953                            Ref::new("TableReferenceSegment").to_matchable(),
2954                        ])
2955                        .to_matchable(),
2956                    ])
2957                    .to_matchable(),
2958                    Ref::new("ValuesClauseSegment").to_matchable(),
2959                    optionally_bracketed(vec![
2960                        Sequence::new(vec![
2961                            Ref::keyword("EXECUTE").to_matchable(),
2962                            Ref::new("FunctionSegment").to_matchable(),
2963                        ])
2964                        .to_matchable(),
2965                    ])
2966                    .to_matchable(),
2967                ])
2968                .to_matchable(),
2969                Ref::new("WithDataClauseSegment").optional().to_matchable(),
2970            ])
2971            .to_matchable()
2972        })
2973        .to_matchable()
2974        .into(),
2975    )]);
2976
2977    // A `ALTER AGGREGATE` statement.
2978    // https://www.postgresql.org/docs/current/sql-alteraggregate.html
2979    postgres.add([(
2980        "AlterAggregateStatementSegment".into(),
2981        Sequence::new(vec![
2982            Ref::keyword("ALTER").to_matchable(),
2983            Ref::keyword("AGGREGATE").to_matchable(),
2984            Ref::new("ObjectReferenceSegment").to_matchable(),
2985            Bracketed::new(vec![
2986                one_of(vec![
2987                    Ref::new("FunctionParameterListGrammar").to_matchable(),
2988                    Anything::new().to_matchable(),
2989                    Ref::new("StarSegment").to_matchable(),
2990                ])
2991                .to_matchable(),
2992            ])
2993            .to_matchable(),
2994            one_of(vec![
2995                Sequence::new(vec![
2996                    Ref::keyword("RENAME").to_matchable(),
2997                    Ref::keyword("TO").to_matchable(),
2998                    Ref::new("FunctionNameSegment").to_matchable(),
2999                ])
3000                .to_matchable(),
3001                Sequence::new(vec![
3002                    Ref::keyword("OWNER").to_matchable(),
3003                    Ref::keyword("TO").to_matchable(),
3004                    one_of(vec![
3005                        Ref::keyword("CURRENT_ROLE").to_matchable(),
3006                        Ref::keyword("CURRENT_USER").to_matchable(),
3007                        Ref::keyword("SESSION_USER").to_matchable(),
3008                        Ref::new("RoleReferenceSegment").to_matchable(),
3009                    ])
3010                    .to_matchable(),
3011                ])
3012                .to_matchable(),
3013                Sequence::new(vec![
3014                    Ref::keyword("SET").to_matchable(),
3015                    Ref::keyword("SCHEMA").to_matchable(),
3016                    Ref::new("SchemaReferenceSegment").to_matchable(),
3017                ])
3018                .to_matchable(),
3019            ])
3020            .to_matchable(),
3021        ])
3022        .to_matchable()
3023        .into(),
3024    )]);
3025
3026    postgres.replace_grammar(
3027        "AlterTableStatementSegment",
3028        Sequence::new(vec![
3029            Ref::keyword("ALTER").to_matchable(),
3030            Ref::keyword("TABLE").to_matchable(),
3031            one_of(vec![
3032                Sequence::new(vec![
3033                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3034                    Ref::keyword("ONLY").optional().to_matchable(),
3035                    Ref::new("TableReferenceSegment").to_matchable(),
3036                    Ref::new("StarSegment").optional().to_matchable(),
3037                    one_of(vec![
3038                        Delimited::new(vec![Ref::new("AlterTableActionSegment").to_matchable()])
3039                            .to_matchable(),
3040                        Sequence::new(vec![
3041                            Ref::keyword("RENAME").to_matchable(),
3042                            Ref::keyword("COLUMN").optional().to_matchable(),
3043                            Ref::new("ColumnReferenceSegment").to_matchable(),
3044                            Ref::keyword("TO").to_matchable(),
3045                            Ref::new("ColumnReferenceSegment").to_matchable(),
3046                        ])
3047                        .to_matchable(),
3048                        Sequence::new(vec![
3049                            Ref::keyword("RENAME").to_matchable(),
3050                            Ref::keyword("CONSTRAINT").to_matchable(),
3051                            Ref::new("ParameterNameSegment").to_matchable(),
3052                            Ref::keyword("TO").to_matchable(),
3053                            Ref::new("ParameterNameSegment").to_matchable(),
3054                        ])
3055                        .to_matchable(),
3056                    ])
3057                    .to_matchable(),
3058                ])
3059                .to_matchable(),
3060                Sequence::new(vec![
3061                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3062                    Ref::new("TableReferenceSegment").to_matchable(),
3063                    one_of(vec![
3064                        Sequence::new(vec![
3065                            Ref::keyword("RENAME").to_matchable(),
3066                            Ref::keyword("TO").to_matchable(),
3067                            Ref::new("TableReferenceSegment").to_matchable(),
3068                        ])
3069                        .to_matchable(),
3070                        Sequence::new(vec![
3071                            Ref::keyword("SET").to_matchable(),
3072                            Ref::keyword("SCHEMA").to_matchable(),
3073                            Ref::new("SchemaReferenceSegment").to_matchable(),
3074                        ])
3075                        .to_matchable(),
3076                        Sequence::new(vec![
3077                            Ref::keyword("ATTACH").to_matchable(),
3078                            Ref::keyword("PARTITION").to_matchable(),
3079                            Ref::new("ParameterNameSegment").to_matchable(),
3080                            one_of(vec![
3081                                Sequence::new(vec![
3082                                    Ref::keyword("FOR").to_matchable(),
3083                                    Ref::keyword("VALUES").to_matchable(),
3084                                    Ref::new("PartitionBoundSpecSegment").to_matchable(),
3085                                ])
3086                                .to_matchable(),
3087                                Ref::keyword("DEFAULT").to_matchable(),
3088                            ])
3089                            .to_matchable(),
3090                        ])
3091                        .to_matchable(),
3092                        Sequence::new(vec![
3093                            Ref::keyword("DETACH").to_matchable(),
3094                            Ref::keyword("PARTITION").to_matchable(),
3095                            Ref::new("ParameterNameSegment").to_matchable(),
3096                            Ref::keyword("CONCURRENTLY").optional().to_matchable(),
3097                            Ref::keyword("FINALIZE").optional().to_matchable(),
3098                        ])
3099                        .to_matchable(),
3100                    ])
3101                    .to_matchable(),
3102                ])
3103                .to_matchable(),
3104                Sequence::new(vec![
3105                    Ref::keyword("ALL").to_matchable(),
3106                    Ref::keyword("IN").to_matchable(),
3107                    Ref::keyword("TABLESPACE").to_matchable(),
3108                    Ref::new("TablespaceReferenceSegment").to_matchable(),
3109                    Sequence::new(vec![
3110                        Ref::keyword("OWNED").to_matchable(),
3111                        Ref::keyword("BY").to_matchable(),
3112                        Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
3113                            .config(|this| this.optional())
3114                            .to_matchable(),
3115                    ])
3116                    .to_matchable(),
3117                    Ref::keyword("SET").to_matchable(),
3118                    Ref::keyword("TABLESPACE").to_matchable(),
3119                    Ref::new("TablespaceReferenceSegment").to_matchable(),
3120                    Ref::keyword("NOWAIT").optional().to_matchable(),
3121                ])
3122                .to_matchable(),
3123            ])
3124            .to_matchable(),
3125        ])
3126        .to_matchable(),
3127    );
3128
3129    postgres.add([
3130        (
3131            "AlterTableActionSegment".into(),
3132            NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_| {
3133                one_of(vec![
3134                    Sequence::new(vec![
3135                        Ref::keyword("ADD").to_matchable(),
3136                        Ref::keyword("COLUMN").optional().to_matchable(),
3137                        Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3138                        Ref::new("ColumnReferenceSegment").to_matchable(),
3139                        Ref::new("DatatypeSegment").to_matchable(),
3140                        Sequence::new(vec![
3141                            Ref::keyword("COLLATE").to_matchable(),
3142                            Ref::new("CollationReferenceSegment").to_matchable(),
3143                        ])
3144                        .config(|this| this.optional())
3145                        .to_matchable(),
3146                        AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()])
3147                            .to_matchable(),
3148                    ])
3149                    .to_matchable(),
3150                    Sequence::new(vec![
3151                        Ref::keyword("DROP").to_matchable(),
3152                        Ref::keyword("COLUMN").optional().to_matchable(),
3153                        Ref::new("IfExistsGrammar").optional().to_matchable(),
3154                        Ref::new("ColumnReferenceSegment").to_matchable(),
3155                        Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3156                    ])
3157                    .to_matchable(),
3158                    Sequence::new(vec![
3159                        Ref::keyword("ALTER").to_matchable(),
3160                        Ref::keyword("COLUMN").optional().to_matchable(),
3161                        Ref::new("ColumnReferenceSegment").to_matchable(),
3162                        one_of(vec![
3163                            Sequence::new(vec![
3164                                Sequence::new(vec![
3165                                    Ref::keyword("SET").to_matchable(),
3166                                    Ref::keyword("DATA").to_matchable(),
3167                                ])
3168                                .config(|this| this.optional())
3169                                .to_matchable(),
3170                                Ref::keyword("TYPE").to_matchable(),
3171                                Ref::new("DatatypeSegment").to_matchable(),
3172                                Sequence::new(vec![
3173                                    Ref::keyword("COLLATE").to_matchable(),
3174                                    Ref::new("CollationReferenceSegment").to_matchable(),
3175                                ])
3176                                .config(|this| this.optional())
3177                                .to_matchable(),
3178                                Sequence::new(vec![
3179                                    Ref::keyword("USING").to_matchable(),
3180                                    one_of(vec![Ref::new("ExpressionSegment").to_matchable()])
3181                                        .to_matchable(),
3182                                ])
3183                                .config(|this| this.optional())
3184                                .to_matchable(),
3185                            ])
3186                            .to_matchable(),
3187                            Sequence::new(vec![
3188                                Ref::keyword("SET").to_matchable(),
3189                                Ref::keyword("DEFAULT").to_matchable(),
3190                                one_of(vec![
3191                                    Ref::new("LiteralGrammar").to_matchable(),
3192                                    Ref::new("FunctionSegment").to_matchable(),
3193                                    Ref::new("BareFunctionSegment").to_matchable(),
3194                                    Ref::new("ExpressionSegment").to_matchable(),
3195                                ])
3196                                .to_matchable(),
3197                            ])
3198                            .to_matchable(),
3199                            Sequence::new(vec![
3200                                Ref::keyword("DROP").to_matchable(),
3201                                Ref::keyword("DEFAULT").to_matchable(),
3202                            ])
3203                            .to_matchable(),
3204                            Sequence::new(vec![
3205                                one_of(vec![
3206                                    Ref::keyword("SET").to_matchable(),
3207                                    Ref::keyword("DROP").to_matchable(),
3208                                ])
3209                                .config(|this| this.optional())
3210                                .to_matchable(),
3211                                Ref::keyword("NOT").to_matchable(),
3212                                Ref::keyword("NULL").to_matchable(),
3213                            ])
3214                            .to_matchable(),
3215                            Sequence::new(vec![
3216                                Ref::keyword("DROP").to_matchable(),
3217                                Ref::keyword("EXPRESSION").to_matchable(),
3218                                Ref::new("IfExistsGrammar").optional().to_matchable(),
3219                            ])
3220                            .to_matchable(),
3221                            Sequence::new(vec![
3222                                Ref::keyword("ADD").to_matchable(),
3223                                Ref::keyword("GENERATED").to_matchable(),
3224                                one_of(vec![
3225                                    Ref::keyword("ALWAYS").to_matchable(),
3226                                    Sequence::new(vec![
3227                                        Ref::keyword("BY").to_matchable(),
3228                                        Ref::keyword("DEFAULT").to_matchable(),
3229                                    ])
3230                                    .to_matchable(),
3231                                ])
3232                                .to_matchable(),
3233                                Ref::keyword("AS").to_matchable(),
3234                                Ref::keyword("IDENTITY").to_matchable(),
3235                                Bracketed::new(vec![
3236                                    AnyNumberOf::new(vec![
3237                                        Ref::new("AlterSequenceOptionsSegment").to_matchable(),
3238                                    ])
3239                                    .config(|this| this.optional())
3240                                    .to_matchable(),
3241                                ])
3242                                .to_matchable(),
3243                            ])
3244                            .to_matchable(),
3245                            Sequence::new(vec![
3246                                one_of(vec![
3247                                    Sequence::new(vec![
3248                                        Ref::keyword("SET").to_matchable(),
3249                                        Ref::keyword("GENERATED").to_matchable(),
3250                                        one_of(vec![
3251                                            Ref::keyword("ALWAYS").to_matchable(),
3252                                            Sequence::new(vec![
3253                                                Ref::keyword("BY").to_matchable(),
3254                                                Ref::keyword("DEFAULT").to_matchable(),
3255                                            ])
3256                                            .to_matchable(),
3257                                        ])
3258                                        .to_matchable(),
3259                                    ])
3260                                    .to_matchable(),
3261                                    Sequence::new(vec![
3262                                        Ref::keyword("SET").to_matchable(),
3263                                        Ref::new("AlterSequenceOptionsSegment").to_matchable(),
3264                                    ])
3265                                    .to_matchable(),
3266                                    Sequence::new(vec![
3267                                        Ref::keyword("RESTART").to_matchable(),
3268                                        Sequence::new(vec![
3269                                            Ref::keyword("WITH").to_matchable(),
3270                                            Ref::new("NumericLiteralSegment").to_matchable(),
3271                                        ])
3272                                        .to_matchable(),
3273                                    ])
3274                                    .to_matchable(),
3275                                ])
3276                                .to_matchable(),
3277                            ])
3278                            .to_matchable(),
3279                            Sequence::new(vec![
3280                                Ref::keyword("DROP").to_matchable(),
3281                                Ref::keyword("IDENTITY").to_matchable(),
3282                                Ref::new("IfExistsGrammar").optional().to_matchable(),
3283                            ])
3284                            .to_matchable(),
3285                            Sequence::new(vec![
3286                                Ref::keyword("SET").to_matchable(),
3287                                Ref::keyword("STATISTICS").to_matchable(),
3288                                Ref::new("NumericLiteralSegment").to_matchable(),
3289                            ])
3290                            .to_matchable(),
3291                            Sequence::new(vec![
3292                                Ref::keyword("SET").to_matchable(),
3293                                Ref::new("RelationOptionsSegment").to_matchable(),
3294                            ])
3295                            .to_matchable(),
3296                            Sequence::new(vec![
3297                                Ref::keyword("RESET").to_matchable(),
3298                                Ref::new("RelationOptionsSegment").to_matchable(),
3299                            ])
3300                            .to_matchable(),
3301                            Sequence::new(vec![
3302                                Ref::keyword("SET").to_matchable(),
3303                                Ref::keyword("STORAGE").to_matchable(),
3304                                one_of(vec![
3305                                    Ref::keyword("PLAIN").to_matchable(),
3306                                    Ref::keyword("EXTERNAL").to_matchable(),
3307                                    Ref::keyword("EXTENDED").to_matchable(),
3308                                    Ref::keyword("MAIN").to_matchable(),
3309                                ])
3310                                .to_matchable(),
3311                            ])
3312                            .to_matchable(),
3313                        ])
3314                        .to_matchable(),
3315                    ])
3316                    .to_matchable(),
3317                    Sequence::new(vec![
3318                        Ref::keyword("ADD").to_matchable(),
3319                        Ref::new("TableConstraintSegment").to_matchable(),
3320                    ])
3321                    .to_matchable(),
3322                    Sequence::new(vec![
3323                        Ref::keyword("ADD").to_matchable(),
3324                        Ref::new("TableConstraintUsingIndexSegment").to_matchable(),
3325                    ])
3326                    .to_matchable(),
3327                    Sequence::new(vec![
3328                        Ref::keyword("ALTER").to_matchable(),
3329                        Ref::keyword("CONSTRAINT").to_matchable(),
3330                        Ref::new("ParameterNameSegment").to_matchable(),
3331                        one_of(vec![
3332                            Ref::keyword("DEFERRABLE").to_matchable(),
3333                            Sequence::new(vec![
3334                                Ref::keyword("NOT").to_matchable(),
3335                                Ref::keyword("DEFERRABLE").to_matchable(),
3336                            ])
3337                            .to_matchable(),
3338                        ])
3339                        .config(|this| this.optional())
3340                        .to_matchable(),
3341                        one_of(vec![
3342                            Sequence::new(vec![
3343                                Ref::keyword("INITIALLY").to_matchable(),
3344                                Ref::keyword("DEFERRED").to_matchable(),
3345                            ])
3346                            .to_matchable(),
3347                            Sequence::new(vec![
3348                                Ref::keyword("INITIALLY").to_matchable(),
3349                                Ref::keyword("IMMEDIATE").to_matchable(),
3350                            ])
3351                            .to_matchable(),
3352                        ])
3353                        .config(|this| this.optional())
3354                        .to_matchable(),
3355                    ])
3356                    .to_matchable(),
3357                    Sequence::new(vec![
3358                        Ref::keyword("VALIDATE").to_matchable(),
3359                        Ref::keyword("CONSTRAINT").to_matchable(),
3360                        Ref::new("ParameterNameSegment").to_matchable(),
3361                    ])
3362                    .to_matchable(),
3363                    Sequence::new(vec![
3364                        Ref::keyword("DROP").to_matchable(),
3365                        Ref::keyword("CONSTRAINT").to_matchable(),
3366                        Ref::new("IfExistsGrammar").optional().to_matchable(),
3367                        Ref::new("ParameterNameSegment").to_matchable(),
3368                        Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3369                    ])
3370                    .to_matchable(),
3371                    Sequence::new(vec![
3372                        one_of(vec![
3373                            Ref::keyword("ENABLE").to_matchable(),
3374                            Ref::keyword("DISABLE").to_matchable(),
3375                        ])
3376                        .to_matchable(),
3377                        Ref::keyword("TRIGGER").to_matchable(),
3378                        one_of(vec![
3379                            Ref::new("ParameterNameSegment").to_matchable(),
3380                            Ref::keyword("ALL").to_matchable(),
3381                            Ref::keyword("USER").to_matchable(),
3382                        ])
3383                        .to_matchable(),
3384                    ])
3385                    .to_matchable(),
3386                    Sequence::new(vec![
3387                        Ref::keyword("ENABLE").to_matchable(),
3388                        one_of(vec![
3389                            Ref::keyword("REPLICA").to_matchable(),
3390                            Ref::keyword("ALWAYS").to_matchable(),
3391                        ])
3392                        .to_matchable(),
3393                        Ref::keyword("TRIGGER").to_matchable(),
3394                        Ref::new("ParameterNameSegment").to_matchable(),
3395                    ])
3396                    .to_matchable(),
3397                    Sequence::new(vec![
3398                        one_of(vec![
3399                            Ref::keyword("ENABLE").to_matchable(),
3400                            Ref::keyword("DISABLE").to_matchable(),
3401                            Sequence::new(vec![
3402                                Ref::keyword("ENABLE").to_matchable(),
3403                                Ref::keyword("REPLICA").to_matchable(),
3404                            ])
3405                            .to_matchable(),
3406                            Sequence::new(vec![
3407                                Ref::keyword("ENABLE").to_matchable(),
3408                                Ref::keyword("RULE").to_matchable(),
3409                            ])
3410                            .to_matchable(),
3411                        ])
3412                        .to_matchable(),
3413                        Ref::keyword("RULE").to_matchable(),
3414                        Ref::new("ParameterNameSegment").to_matchable(),
3415                    ])
3416                    .to_matchable(),
3417                    Sequence::new(vec![
3418                        one_of(vec![
3419                            Ref::keyword("DISABLE").to_matchable(),
3420                            Ref::keyword("ENABLE").to_matchable(),
3421                            Ref::keyword("FORCE").to_matchable(),
3422                            Sequence::new(vec![
3423                                Ref::keyword("NO").to_matchable(),
3424                                Ref::keyword("FORCE").to_matchable(),
3425                            ])
3426                            .to_matchable(),
3427                        ])
3428                        .to_matchable(),
3429                        Ref::keyword("ROW").to_matchable(),
3430                        Ref::keyword("LEVEL").to_matchable(),
3431                        Ref::keyword("SECURITY").to_matchable(),
3432                    ])
3433                    .to_matchable(),
3434                    Sequence::new(vec![
3435                        Ref::keyword("CLUSTER").to_matchable(),
3436                        Ref::keyword("ON").to_matchable(),
3437                        Ref::new("ParameterNameSegment").to_matchable(),
3438                    ])
3439                    .to_matchable(),
3440                    Sequence::new(vec![
3441                        Ref::keyword("SET").to_matchable(),
3442                        Ref::keyword("WITHOUT").to_matchable(),
3443                        one_of(vec![
3444                            Ref::keyword("CLUSTER").to_matchable(),
3445                            Ref::keyword("OIDS").to_matchable(),
3446                        ])
3447                        .to_matchable(),
3448                    ])
3449                    .to_matchable(),
3450                    Sequence::new(vec![
3451                        Ref::keyword("SET").to_matchable(),
3452                        Ref::keyword("TABLESPACE").to_matchable(),
3453                        Ref::new("TablespaceReferenceSegment").to_matchable(),
3454                    ])
3455                    .to_matchable(),
3456                    Sequence::new(vec![
3457                        Ref::keyword("SET").to_matchable(),
3458                        one_of(vec![
3459                            Ref::keyword("LOGGED").to_matchable(),
3460                            Ref::keyword("UNLOGGED").to_matchable(),
3461                        ])
3462                        .to_matchable(),
3463                    ])
3464                    .to_matchable(),
3465                    Sequence::new(vec![
3466                        Ref::keyword("SET").to_matchable(),
3467                        Ref::new("RelationOptionsSegment").to_matchable(),
3468                    ])
3469                    .to_matchable(),
3470                    Sequence::new(vec![
3471                        Ref::keyword("RESET").to_matchable(),
3472                        Ref::new("RelationOptionsSegment").to_matchable(),
3473                    ])
3474                    .to_matchable(),
3475                    Sequence::new(vec![
3476                        Ref::keyword("NO").optional().to_matchable(),
3477                        Ref::keyword("INHERIT").to_matchable(),
3478                        Ref::new("TableReferenceSegment").to_matchable(),
3479                    ])
3480                    .to_matchable(),
3481                    Sequence::new(vec![
3482                        Ref::keyword("OF").to_matchable(),
3483                        Ref::new("ParameterNameSegment").to_matchable(),
3484                    ])
3485                    .to_matchable(),
3486                    Sequence::new(vec![
3487                        Ref::keyword("NOT").to_matchable(),
3488                        Ref::keyword("OF").to_matchable(),
3489                    ])
3490                    .to_matchable(),
3491                    Sequence::new(vec![
3492                        Ref::keyword("OWNER").to_matchable(),
3493                        Ref::keyword("TO").to_matchable(),
3494                        one_of(vec![
3495                            Ref::new("ParameterNameSegment").to_matchable(),
3496                            Ref::keyword("CURRENT_ROLE").to_matchable(),
3497                            Ref::keyword("CURRENT_USER").to_matchable(),
3498                            Ref::keyword("SESSION_USER").to_matchable(),
3499                        ])
3500                        .to_matchable(),
3501                    ])
3502                    .to_matchable(),
3503                    Sequence::new(vec![
3504                        Ref::keyword("REPLICA").to_matchable(),
3505                        Ref::keyword("IDENTITY").to_matchable(),
3506                        one_of(vec![
3507                            Ref::keyword("DEFAULT").to_matchable(),
3508                            Sequence::new(vec![
3509                                Ref::keyword("USING").to_matchable(),
3510                                Ref::keyword("INDEX").to_matchable(),
3511                                Ref::new("IndexReferenceSegment").to_matchable(),
3512                            ])
3513                            .to_matchable(),
3514                            Ref::keyword("FULL").to_matchable(),
3515                            Ref::keyword("NOTHING").to_matchable(),
3516                        ])
3517                        .to_matchable(),
3518                    ])
3519                    .to_matchable(),
3520                ])
3521                .to_matchable()
3522            })
3523            .to_matchable()
3524            .into(),
3525        ),
3526        (
3527            "VersionIdentifierSegment".into(),
3528            NodeMatcher::new(SyntaxKind::VersionIdentifier, |_| {
3529                one_of(vec![
3530                    Ref::new("QuotedLiteralSegment").to_matchable(),
3531                    Ref::new("NakedIdentifierSegment").to_matchable(),
3532                ])
3533                .to_matchable()
3534            })
3535            .to_matchable()
3536            .into(),
3537        ),
3538        (
3539            "CreateExtensionStatementSegment".into(),
3540            NodeMatcher::new(SyntaxKind::CreateExtensionStatement, |_| {
3541                Sequence::new(vec![
3542                    Ref::keyword("CREATE").to_matchable(),
3543                    Ref::keyword("EXTENSION").to_matchable(),
3544                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3545                    Ref::new("ExtensionReferenceSegment").to_matchable(),
3546                    Ref::keyword("WITH").optional().to_matchable(),
3547                    Sequence::new(vec![
3548                        Ref::keyword("SCHEMA").to_matchable(),
3549                        Ref::new("SchemaReferenceSegment").to_matchable(),
3550                    ])
3551                    .config(|this| this.optional())
3552                    .to_matchable(),
3553                    Sequence::new(vec![
3554                        Ref::keyword("VERSION").to_matchable(),
3555                        Ref::new("VersionIdentifierSegment").to_matchable(),
3556                    ])
3557                    .config(|this| this.optional())
3558                    .to_matchable(),
3559                    Sequence::new(vec![
3560                        Ref::keyword("FROM").to_matchable(),
3561                        Ref::new("VersionIdentifierSegment").to_matchable(),
3562                    ])
3563                    .config(|this| this.optional())
3564                    .to_matchable(),
3565                ])
3566                .to_matchable()
3567            })
3568            .to_matchable()
3569            .into(),
3570        ),
3571        (
3572            "DropExtensionStatementSegment".into(),
3573            NodeMatcher::new(SyntaxKind::DropExtensionStatement, |_| {
3574                Sequence::new(vec![
3575                    Ref::keyword("DROP").to_matchable(),
3576                    Ref::keyword("EXTENSION").to_matchable(),
3577                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3578                    Ref::new("ExtensionReferenceSegment").to_matchable(),
3579                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3580                ])
3581                .to_matchable()
3582            })
3583            .to_matchable()
3584            .into(),
3585        ),
3586        (
3587            "PublicationReferenceSegment".into(),
3588            NodeMatcher::new(SyntaxKind::PublicationReference, |_| {
3589                Ref::new("SingleIdentifierGrammar").to_matchable()
3590            })
3591            .to_matchable()
3592            .into(),
3593        ),
3594        (
3595            "PublicationTableSegment".into(),
3596            NodeMatcher::new(SyntaxKind::PublicationTable, |_| {
3597                Sequence::new(vec![
3598                    Ref::new("ExtendedTableReferenceGrammar").to_matchable(),
3599                    Ref::new("BracketedColumnReferenceListGrammar")
3600                        .optional()
3601                        .to_matchable(),
3602                    Sequence::new(vec![
3603                        Ref::keyword("WHERE").to_matchable(),
3604                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
3605                            .to_matchable(),
3606                    ])
3607                    .config(|this| this.optional())
3608                    .to_matchable(),
3609                ])
3610                .to_matchable()
3611            })
3612            .to_matchable()
3613            .into(),
3614        ),
3615        (
3616            "PublicationObjectsSegment".into(),
3617            NodeMatcher::new(SyntaxKind::PublicationObjects, |_| {
3618                one_of(vec![
3619                    Sequence::new(vec![
3620                        Ref::keyword("TABLE").to_matchable(),
3621                        Delimited::new(vec![Ref::new("PublicationTableSegment").to_matchable()])
3622                            .config(|this| {
3623                                this.terminators = vec![
3624                                    Sequence::new(vec![
3625                                        Ref::new("CommaSegment").to_matchable(),
3626                                        one_of(vec![
3627                                            Ref::keyword("TABLE").to_matchable(),
3628                                            Ref::keyword("TABLES").to_matchable(),
3629                                        ])
3630                                        .to_matchable(),
3631                                    ])
3632                                    .to_matchable(),
3633                                ];
3634                            })
3635                            .to_matchable(),
3636                    ])
3637                    .to_matchable(),
3638                    Sequence::new(vec![
3639                        Ref::keyword("TABLES").to_matchable(),
3640                        Ref::keyword("IN").to_matchable(),
3641                        Ref::keyword("SCHEMA").to_matchable(),
3642                        Delimited::new(vec![
3643                            one_of(vec![
3644                                Ref::new("SchemaReferenceSegment").to_matchable(),
3645                                Ref::keyword("CURRENT_SCHEMA").to_matchable(),
3646                            ])
3647                            .to_matchable(),
3648                        ])
3649                        .config(|this| {
3650                            this.terminators = vec![
3651                                Sequence::new(vec![
3652                                    Ref::new("CommaSegment").to_matchable(),
3653                                    one_of(vec![
3654                                        Ref::keyword("TABLE").to_matchable(),
3655                                        Ref::keyword("TABLES").to_matchable(),
3656                                    ])
3657                                    .to_matchable(),
3658                                ])
3659                                .to_matchable(),
3660                            ];
3661                        })
3662                        .to_matchable(),
3663                    ])
3664                    .to_matchable(),
3665                ])
3666                .to_matchable()
3667            })
3668            .to_matchable()
3669            .into(),
3670        ),
3671        (
3672            "CreatePublicationStatementSegment".into(),
3673            NodeMatcher::new(SyntaxKind::CreatePublicationStatement, |_| {
3674                Sequence::new(vec![
3675                    Ref::keyword("CREATE").to_matchable(),
3676                    Ref::keyword("PUBLICATION").to_matchable(),
3677                    Ref::new("PublicationReferenceSegment").to_matchable(),
3678                    one_of(vec![
3679                        Sequence::new(vec![
3680                            Ref::keyword("FOR").to_matchable(),
3681                            Ref::keyword("ALL").to_matchable(),
3682                            Ref::keyword("TABLES").to_matchable(),
3683                        ])
3684                        .to_matchable(),
3685                        Sequence::new(vec![
3686                            Ref::keyword("FOR").to_matchable(),
3687                            Delimited::new(vec![
3688                                Ref::new("PublicationObjectsSegment").to_matchable(),
3689                            ])
3690                            .to_matchable(),
3691                        ])
3692                        .to_matchable(),
3693                    ])
3694                    .config(|this| this.optional())
3695                    .to_matchable(),
3696                    Sequence::new(vec![
3697                        Ref::keyword("WITH").to_matchable(),
3698                        Ref::new("DefinitionParametersSegment").to_matchable(),
3699                    ])
3700                    .config(|this| this.optional())
3701                    .to_matchable(),
3702                ])
3703                .to_matchable()
3704            })
3705            .to_matchable()
3706            .into(),
3707        ),
3708        (
3709            "AlterPublicationStatementSegment".into(),
3710            NodeMatcher::new(SyntaxKind::AlterPublicationStatement, |_| {
3711                Sequence::new(vec![
3712                    Ref::keyword("ALTER").to_matchable(),
3713                    Ref::keyword("PUBLICATION").to_matchable(),
3714                    Ref::new("PublicationReferenceSegment").to_matchable(),
3715                    one_of(vec![
3716                        Sequence::new(vec![
3717                            Ref::keyword("SET").to_matchable(),
3718                            Ref::new("DefinitionParametersSegment").to_matchable(),
3719                        ])
3720                        .to_matchable(),
3721                        Sequence::new(vec![
3722                            Ref::keyword("ADD").to_matchable(),
3723                            Delimited::new(vec![
3724                                Ref::new("PublicationObjectsSegment").to_matchable(),
3725                            ])
3726                            .to_matchable(),
3727                        ])
3728                        .to_matchable(),
3729                        Sequence::new(vec![
3730                            Ref::keyword("SET").to_matchable(),
3731                            Delimited::new(vec![
3732                                Ref::new("PublicationObjectsSegment").to_matchable(),
3733                            ])
3734                            .to_matchable(),
3735                        ])
3736                        .to_matchable(),
3737                        Sequence::new(vec![
3738                            Ref::keyword("DROP").to_matchable(),
3739                            Delimited::new(vec![
3740                                Ref::new("PublicationObjectsSegment").to_matchable(),
3741                            ])
3742                            .to_matchable(),
3743                        ])
3744                        .to_matchable(),
3745                        Sequence::new(vec![
3746                            Ref::keyword("RENAME").to_matchable(),
3747                            Ref::keyword("TO").to_matchable(),
3748                            Ref::new("PublicationReferenceSegment").to_matchable(),
3749                        ])
3750                        .to_matchable(),
3751                        Sequence::new(vec![
3752                            Ref::keyword("OWNER").to_matchable(),
3753                            Ref::keyword("TO").to_matchable(),
3754                            one_of(vec![
3755                                Ref::keyword("CURRENT_ROLE").to_matchable(),
3756                                Ref::keyword("CURRENT_USER").to_matchable(),
3757                                Ref::keyword("SESSION_USER").to_matchable(),
3758                                Ref::new("RoleReferenceSegment").to_matchable(),
3759                            ])
3760                            .to_matchable(),
3761                        ])
3762                        .to_matchable(),
3763                    ])
3764                    .to_matchable(),
3765                ])
3766                .to_matchable()
3767            })
3768            .to_matchable()
3769            .into(),
3770        ),
3771    ]);
3772
3773    postgres.add([
3774        (
3775            "DropPublicationStatementSegment".into(),
3776            NodeMatcher::new(SyntaxKind::DropPublicationStatement, |_| {
3777                Sequence::new(vec![
3778                    Ref::keyword("DROP").to_matchable(),
3779                    Ref::keyword("PUBLICATION").to_matchable(),
3780                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3781                    Delimited::new(vec![Ref::new("PublicationReferenceSegment").to_matchable()])
3782                        .to_matchable(),
3783                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3784                ])
3785                .to_matchable()
3786            })
3787            .to_matchable()
3788            .into(),
3789        ),
3790        (
3791            "CreateMaterializedViewStatementSegment".into(),
3792            NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_| {
3793                Sequence::new(vec![
3794                    Ref::keyword("CREATE").to_matchable(),
3795                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
3796                    Ref::keyword("MATERIALIZED").to_matchable(),
3797                    Ref::keyword("VIEW").to_matchable(),
3798                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3799                    Ref::new("TableReferenceSegment").to_matchable(),
3800                    Ref::new("BracketedColumnReferenceListGrammar")
3801                        .optional()
3802                        .to_matchable(),
3803                    Sequence::new(vec![
3804                        Ref::keyword("USING").to_matchable(),
3805                        Ref::new("ParameterNameSegment").to_matchable(),
3806                    ])
3807                    .config(|this| this.optional())
3808                    .to_matchable(),
3809                    Sequence::new(vec![
3810                        Ref::keyword("WITH").to_matchable(),
3811                        Ref::new("RelationOptionsSegment").to_matchable(),
3812                    ])
3813                    .config(|this| this.optional())
3814                    .to_matchable(),
3815                    Sequence::new(vec![
3816                        Ref::keyword("TABLESPACE").to_matchable(),
3817                        Ref::new("TablespaceReferenceSegment").to_matchable(),
3818                    ])
3819                    .config(|this| this.optional())
3820                    .to_matchable(),
3821                    Ref::keyword("AS").to_matchable(),
3822                    one_of(vec![
3823                        optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
3824                            .to_matchable(),
3825                        optionally_bracketed(vec![
3826                            Sequence::new(vec![
3827                                Ref::keyword("TABLE").to_matchable(),
3828                                Ref::new("TableReferenceSegment").to_matchable(),
3829                            ])
3830                            .to_matchable(),
3831                        ])
3832                        .to_matchable(),
3833                        Ref::new("ValuesClauseSegment").to_matchable(),
3834                        optionally_bracketed(vec![
3835                            Sequence::new(vec![
3836                                Ref::keyword("EXECUTE").to_matchable(),
3837                                Ref::new("FunctionSegment").to_matchable(),
3838                            ])
3839                            .to_matchable(),
3840                        ])
3841                        .to_matchable(),
3842                    ])
3843                    .to_matchable(),
3844                    Ref::new("WithDataClauseSegment").optional().to_matchable(),
3845                ])
3846                .to_matchable()
3847            })
3848            .to_matchable()
3849            .into(),
3850        ),
3851        (
3852            "AlterMaterializedViewStatementSegment".into(),
3853            NodeMatcher::new(SyntaxKind::AlterMaterializedViewStatement, |_| {
3854                Sequence::new(vec![
3855                    Ref::keyword("ALTER").to_matchable(),
3856                    Ref::keyword("MATERIALIZED").to_matchable(),
3857                    Ref::keyword("VIEW").to_matchable(),
3858                    one_of(vec![
3859                        Sequence::new(vec![
3860                            Ref::new("IfExistsGrammar").optional().to_matchable(),
3861                            Ref::new("TableReferenceSegment").to_matchable(),
3862                            one_of(vec![
3863                                Delimited::new(vec![
3864                                    Ref::new("AlterMaterializedViewActionSegment").to_matchable(),
3865                                ])
3866                                .to_matchable(),
3867                                Sequence::new(vec![
3868                                    Ref::keyword("RENAME").to_matchable(),
3869                                    Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()])
3870                                        .config(|this| this.optional())
3871                                        .to_matchable(),
3872                                    Ref::new("ColumnReferenceSegment").to_matchable(),
3873                                    Ref::keyword("TO").to_matchable(),
3874                                    Ref::new("ColumnReferenceSegment").to_matchable(),
3875                                ])
3876                                .to_matchable(),
3877                                Sequence::new(vec![
3878                                    Ref::keyword("RENAME").to_matchable(),
3879                                    Ref::keyword("TO").to_matchable(),
3880                                    Ref::new("TableReferenceSegment").to_matchable(),
3881                                ])
3882                                .to_matchable(),
3883                                Sequence::new(vec![
3884                                    Ref::keyword("SET").to_matchable(),
3885                                    Ref::keyword("SCHEMA").to_matchable(),
3886                                    Ref::new("SchemaReferenceSegment").to_matchable(),
3887                                ])
3888                                .to_matchable(),
3889                            ])
3890                            .to_matchable(),
3891                        ])
3892                        .to_matchable(),
3893                        Sequence::new(vec![
3894                            Ref::new("TableReferenceSegment").to_matchable(),
3895                            Ref::keyword("NO").optional().to_matchable(),
3896                            Ref::keyword("DEPENDS").to_matchable(),
3897                            Ref::keyword("ON").to_matchable(),
3898                            Ref::keyword("EXTENSION").to_matchable(),
3899                            Ref::new("ExtensionReferenceSegment").to_matchable(),
3900                        ])
3901                        .to_matchable(),
3902                        Sequence::new(vec![
3903                            Ref::keyword("ALL").to_matchable(),
3904                            Ref::keyword("IN").to_matchable(),
3905                            Ref::keyword("TABLESPACE").to_matchable(),
3906                            Ref::new("TablespaceReferenceSegment").to_matchable(),
3907                            Sequence::new(vec![
3908                                Ref::keyword("OWNED").to_matchable(),
3909                                Ref::keyword("BY").to_matchable(),
3910                                Delimited::new(vec![
3911                                    Ref::new("ObjectReferenceSegment").to_matchable(),
3912                                ])
3913                                .to_matchable(),
3914                            ])
3915                            .config(|this| this.optional())
3916                            .to_matchable(),
3917                            Ref::keyword("SET").to_matchable(),
3918                            Ref::keyword("TABLESPACE").to_matchable(),
3919                            Ref::new("TablespaceReferenceSegment").to_matchable(),
3920                            Sequence::new(vec![Ref::keyword("NOWAIT").to_matchable()])
3921                                .config(|this| this.optional())
3922                                .to_matchable(),
3923                        ])
3924                        .to_matchable(),
3925                    ])
3926                    .to_matchable(),
3927                ])
3928                .to_matchable()
3929            })
3930            .to_matchable()
3931            .into(),
3932        ),
3933        (
3934            "AlterMaterializedViewActionSegment".into(),
3935            NodeMatcher::new(SyntaxKind::AlterMaterializedViewActionSegment, |_| {
3936                one_of(vec![
3937                    Sequence::new(vec![
3938                        Ref::keyword("ALTER").to_matchable(),
3939                        Ref::keyword("COLUMN").optional().to_matchable(),
3940                        Ref::new("ColumnReferenceSegment").to_matchable(),
3941                        one_of(vec![
3942                            Sequence::new(vec![
3943                                Ref::keyword("SET").to_matchable(),
3944                                Ref::keyword("STATISTICS").to_matchable(),
3945                                Ref::new("NumericLiteralSegment").to_matchable(),
3946                            ])
3947                            .to_matchable(),
3948                            Sequence::new(vec![
3949                                Ref::keyword("SET").to_matchable(),
3950                                Bracketed::new(vec![
3951                                    Delimited::new(vec![
3952                                        Sequence::new(vec![
3953                                            Ref::new("ParameterNameSegment").to_matchable(),
3954                                            Ref::new("EqualsSegment").to_matchable(),
3955                                            Ref::new("LiteralGrammar").to_matchable(),
3956                                        ])
3957                                        .to_matchable(),
3958                                    ])
3959                                    .to_matchable(),
3960                                ])
3961                                .to_matchable(),
3962                            ])
3963                            .to_matchable(),
3964                            Sequence::new(vec![
3965                                Ref::keyword("RESET").to_matchable(),
3966                                Bracketed::new(vec![
3967                                    Delimited::new(vec![
3968                                        Ref::new("ParameterNameSegment").to_matchable(),
3969                                    ])
3970                                    .to_matchable(),
3971                                ])
3972                                .to_matchable(),
3973                            ])
3974                            .to_matchable(),
3975                            Sequence::new(vec![
3976                                Ref::keyword("SET").to_matchable(),
3977                                Ref::keyword("STORAGE").to_matchable(),
3978                                one_of(vec![
3979                                    Ref::keyword("PLAIN").to_matchable(),
3980                                    Ref::keyword("EXTERNAL").to_matchable(),
3981                                    Ref::keyword("EXTENDED").to_matchable(),
3982                                    Ref::keyword("MAIN").to_matchable(),
3983                                ])
3984                                .to_matchable(),
3985                            ])
3986                            .to_matchable(),
3987                            Sequence::new(vec![
3988                                Ref::keyword("SET").to_matchable(),
3989                                Ref::keyword("COMPRESSION").to_matchable(),
3990                                Ref::new("ParameterNameSegment").to_matchable(),
3991                            ])
3992                            .to_matchable(),
3993                        ])
3994                        .to_matchable(),
3995                    ])
3996                    .to_matchable(),
3997                    Sequence::new(vec![
3998                        Ref::keyword("CLUSTER").to_matchable(),
3999                        Ref::keyword("ON").to_matchable(),
4000                        Ref::new("ParameterNameSegment").to_matchable(),
4001                    ])
4002                    .to_matchable(),
4003                    Sequence::new(vec![
4004                        Ref::keyword("SET").to_matchable(),
4005                        Ref::keyword("WITHOUT").to_matchable(),
4006                        Ref::keyword("CLUSTER").to_matchable(),
4007                    ])
4008                    .to_matchable(),
4009                    Sequence::new(vec![
4010                        Ref::keyword("SET").to_matchable(),
4011                        Bracketed::new(vec![
4012                            Delimited::new(vec![
4013                                Sequence::new(vec![
4014                                    Ref::new("ParameterNameSegment").to_matchable(),
4015                                    Sequence::new(vec![
4016                                        Ref::new("EqualsSegment").to_matchable(),
4017                                        Ref::new("LiteralGrammar").to_matchable(),
4018                                    ])
4019                                    .config(|this| this.optional())
4020                                    .to_matchable(),
4021                                ])
4022                                .to_matchable(),
4023                            ])
4024                            .to_matchable(),
4025                        ])
4026                        .to_matchable(),
4027                    ])
4028                    .to_matchable(),
4029                    Sequence::new(vec![
4030                        Ref::keyword("RESET").to_matchable(),
4031                        Bracketed::new(vec![
4032                            Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()])
4033                                .to_matchable(),
4034                        ])
4035                        .to_matchable(),
4036                    ])
4037                    .to_matchable(),
4038                    Sequence::new(vec![
4039                        Ref::keyword("OWNER").to_matchable(),
4040                        Ref::keyword("TO").to_matchable(),
4041                        one_of(vec![
4042                            Ref::new("ObjectReferenceSegment").to_matchable(),
4043                            Ref::keyword("CURRENT_ROLE").to_matchable(),
4044                            Ref::keyword("CURRENT_USER").to_matchable(),
4045                            Ref::keyword("SESSION_USER").to_matchable(),
4046                        ])
4047                        .to_matchable(),
4048                    ])
4049                    .to_matchable(),
4050                ])
4051                .to_matchable()
4052            })
4053            .to_matchable()
4054            .into(),
4055        ),
4056        (
4057            "RefreshMaterializedViewStatementSegment".into(),
4058            NodeMatcher::new(SyntaxKind::RefreshMaterializedViewStatement, |_| {
4059                Sequence::new(vec![
4060                    Ref::keyword("REFRESH").to_matchable(),
4061                    Ref::keyword("MATERIALIZED").to_matchable(),
4062                    Ref::keyword("VIEW").to_matchable(),
4063                    Ref::keyword("CONCURRENTLY").optional().to_matchable(),
4064                    Ref::new("TableReferenceSegment").to_matchable(),
4065                    Ref::new("WithDataClauseSegment").optional().to_matchable(),
4066                ])
4067                .to_matchable()
4068            })
4069            .to_matchable()
4070            .into(),
4071        ),
4072        (
4073            "DropMaterializedViewStatementSegment".into(),
4074            NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_| {
4075                Sequence::new(vec![
4076                    Ref::keyword("DROP").to_matchable(),
4077                    Ref::keyword("MATERIALIZED").to_matchable(),
4078                    Ref::keyword("VIEW").to_matchable(),
4079                    Ref::new("IfExistsGrammar").optional().to_matchable(),
4080                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
4081                        .to_matchable(),
4082                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
4083                ])
4084                .to_matchable()
4085            })
4086            .to_matchable()
4087            .into(),
4088        ),
4089        (
4090            "WithCheckOptionSegment".into(),
4091            NodeMatcher::new(SyntaxKind::WithCheckOption, |_| {
4092                Sequence::new(vec![
4093                    Ref::keyword("WITH").to_matchable(),
4094                    one_of(vec![
4095                        Ref::keyword("CASCADED").to_matchable(),
4096                        Ref::keyword("LOCAL").to_matchable(),
4097                    ])
4098                    .to_matchable(),
4099                    Ref::keyword("CHECK").to_matchable(),
4100                    Ref::keyword("OPTION").to_matchable(),
4101                ])
4102                .to_matchable()
4103            })
4104            .to_matchable()
4105            .into(),
4106        ),
4107        (
4108            "AlterPolicyStatementSegment".into(),
4109            NodeMatcher::new(SyntaxKind::AlterPolicyStatement, |_| {
4110                Sequence::new(vec![
4111                    Ref::keyword("ALTER").to_matchable(),
4112                    Ref::keyword("POLICY").to_matchable(),
4113                    Ref::new("ObjectReferenceSegment").to_matchable(),
4114                    Ref::keyword("ON").to_matchable(),
4115                    Ref::new("TableReferenceSegment").to_matchable(),
4116                    one_of(vec![
4117                        Sequence::new(vec![
4118                            Ref::keyword("RENAME").to_matchable(),
4119                            Ref::keyword("TO").to_matchable(),
4120                            Ref::new("ObjectReferenceSegment").to_matchable(),
4121                        ])
4122                        .to_matchable(),
4123                        Sequence::new(vec![
4124                            Ref::keyword("TO").to_matchable(),
4125                            Delimited::new(vec![
4126                                one_of(vec![
4127                                    Ref::new("RoleReferenceSegment").to_matchable(),
4128                                    Ref::keyword("PUBLIC").to_matchable(),
4129                                    Ref::keyword("CURRENT_ROLE").to_matchable(),
4130                                    Ref::keyword("CURRENT_USER").to_matchable(),
4131                                    Ref::keyword("SESSION_USER").to_matchable(),
4132                                ])
4133                                .to_matchable(),
4134                            ])
4135                            .to_matchable(),
4136                        ])
4137                        .config(|this| this.optional())
4138                        .to_matchable(),
4139                        Sequence::new(vec![
4140                            Ref::keyword("USING").to_matchable(),
4141                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4142                                .to_matchable(),
4143                        ])
4144                        .config(|this| this.optional())
4145                        .to_matchable(),
4146                        Sequence::new(vec![
4147                            Ref::keyword("WITH").to_matchable(),
4148                            Ref::keyword("CHECK").to_matchable(),
4149                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4150                                .to_matchable(),
4151                        ])
4152                        .config(|this| this.optional())
4153                        .to_matchable(),
4154                    ])
4155                    .to_matchable(),
4156                ])
4157                .to_matchable()
4158            })
4159            .to_matchable()
4160            .into(),
4161        ),
4162    ]);
4163
4164    postgres.add([
4165        (
4166            "CreateViewStatementSegment".into(),
4167            NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| {
4168                Sequence::new(vec![
4169                    Ref::keyword("CREATE").to_matchable(),
4170                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
4171                    Ref::new("TemporaryGrammar").optional().to_matchable(),
4172                    Ref::keyword("RECURSIVE").optional().to_matchable(),
4173                    Ref::keyword("VIEW").to_matchable(),
4174                    Ref::new("TableReferenceSegment").to_matchable(),
4175                    Ref::new("BracketedColumnReferenceListGrammar")
4176                        .optional()
4177                        .to_matchable(),
4178                    Sequence::new(vec![
4179                        Ref::keyword("WITH").to_matchable(),
4180                        Ref::new("RelationOptionsSegment").to_matchable(),
4181                    ])
4182                    .config(|this| this.optional())
4183                    .to_matchable(),
4184                    Ref::keyword("AS").to_matchable(),
4185                    one_of(vec![
4186                        optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
4187                            .to_matchable(),
4188                        Ref::new("ValuesClauseSegment").to_matchable(),
4189                    ])
4190                    .to_matchable(),
4191                    Ref::new("WithCheckOptionSegment").optional().to_matchable(),
4192                ])
4193                .to_matchable()
4194            })
4195            .to_matchable()
4196            .into(),
4197        ),
4198        (
4199            "AlterViewStatementSegment".into(),
4200            NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| {
4201                Sequence::new(vec![
4202                    Ref::keyword("ALTER").to_matchable(),
4203                    Ref::keyword("VIEW").to_matchable(),
4204                    Ref::new("IfExistsGrammar").optional().to_matchable(),
4205                    Ref::new("TableReferenceSegment").to_matchable(),
4206                    one_of(vec![
4207                        Sequence::new(vec![
4208                            Ref::keyword("ALTER").to_matchable(),
4209                            Ref::keyword("COLUMN").optional().to_matchable(),
4210                            Ref::new("ColumnReferenceSegment").to_matchable(),
4211                            one_of(vec![
4212                                Sequence::new(vec![
4213                                    Ref::keyword("SET").to_matchable(),
4214                                    Ref::keyword("DEFAULT").to_matchable(),
4215                                    one_of(vec![
4216                                        Ref::new("LiteralGrammar").to_matchable(),
4217                                        Ref::new("FunctionSegment").to_matchable(),
4218                                        Ref::new("BareFunctionSegment").to_matchable(),
4219                                        Ref::new("ExpressionSegment").to_matchable(),
4220                                    ])
4221                                    .to_matchable(),
4222                                ])
4223                                .to_matchable(),
4224                                Sequence::new(vec![
4225                                    Ref::keyword("DROP").to_matchable(),
4226                                    Ref::keyword("DEFAULT").to_matchable(),
4227                                ])
4228                                .to_matchable(),
4229                            ])
4230                            .to_matchable(),
4231                        ])
4232                        .to_matchable(),
4233                        Sequence::new(vec![
4234                            Ref::keyword("OWNER").to_matchable(),
4235                            Ref::keyword("TO").to_matchable(),
4236                            one_of(vec![
4237                                Ref::new("ObjectReferenceSegment").to_matchable(),
4238                                Ref::keyword("CURRENT_ROLE").to_matchable(),
4239                                Ref::keyword("CURRENT_USER").to_matchable(),
4240                                Ref::keyword("SESSION_USER").to_matchable(),
4241                            ])
4242                            .to_matchable(),
4243                        ])
4244                        .to_matchable(),
4245                        Sequence::new(vec![
4246                            Ref::keyword("RENAME").to_matchable(),
4247                            Ref::keyword("COLUMN").optional().to_matchable(),
4248                            Ref::new("ColumnReferenceSegment").to_matchable(),
4249                            Ref::keyword("TO").to_matchable(),
4250                            Ref::new("ColumnReferenceSegment").to_matchable(),
4251                        ])
4252                        .to_matchable(),
4253                        Sequence::new(vec![
4254                            Ref::keyword("RENAME").to_matchable(),
4255                            Ref::keyword("TO").to_matchable(),
4256                            Ref::new("TableReferenceSegment").to_matchable(),
4257                        ])
4258                        .to_matchable(),
4259                        Sequence::new(vec![
4260                            Ref::keyword("SET").to_matchable(),
4261                            Ref::keyword("SCHEMA").to_matchable(),
4262                            Ref::new("SchemaReferenceSegment").to_matchable(),
4263                        ])
4264                        .to_matchable(),
4265                        Sequence::new(vec![
4266                            Ref::keyword("SET").to_matchable(),
4267                            Bracketed::new(vec![
4268                                Delimited::new(vec![
4269                                    Sequence::new(vec![
4270                                        Ref::new("ParameterNameSegment").to_matchable(),
4271                                        Sequence::new(vec![
4272                                            Ref::new("EqualsSegment").to_matchable(),
4273                                            Ref::new("LiteralGrammar").to_matchable(),
4274                                        ])
4275                                        .config(|this| this.optional())
4276                                        .to_matchable(),
4277                                    ])
4278                                    .to_matchable(),
4279                                ])
4280                                .to_matchable(),
4281                            ])
4282                            .to_matchable(),
4283                        ])
4284                        .to_matchable(),
4285                        Sequence::new(vec![
4286                            Ref::keyword("RESET").to_matchable(),
4287                            Bracketed::new(vec![
4288                                Delimited::new(vec![
4289                                    Ref::new("ParameterNameSegment").to_matchable(),
4290                                ])
4291                                .to_matchable(),
4292                            ])
4293                            .to_matchable(),
4294                        ])
4295                        .to_matchable(),
4296                    ])
4297                    .to_matchable(),
4298                ])
4299                .to_matchable()
4300            })
4301            .to_matchable()
4302            .into(),
4303        ),
4304    ]);
4305
4306    postgres.add([
4307        (
4308            "DropViewStatementSegment".into(),
4309            NodeMatcher::new(SyntaxKind::DropViewStatement, |_| {
4310                Sequence::new(vec![
4311                    Ref::keyword("DROP").to_matchable(),
4312                    Ref::keyword("VIEW").to_matchable(),
4313                    Ref::new("IfExistsGrammar").optional().to_matchable(),
4314                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
4315                        .to_matchable(),
4316                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
4317                ])
4318                .to_matchable()
4319            })
4320            .to_matchable()
4321            .into(),
4322        ),
4323        (
4324            "CreateDatabaseStatementSegment".into(),
4325            NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_| {
4326                Sequence::new(vec![
4327                    Ref::keyword("CREATE").to_matchable(),
4328                    Ref::keyword("DATABASE").to_matchable(),
4329                    Ref::new("DatabaseReferenceSegment").to_matchable(),
4330                    Ref::keyword("WITH").optional().to_matchable(),
4331                    AnyNumberOf::new(vec![
4332                        Sequence::new(vec![
4333                            Ref::keyword("OWNER").to_matchable(),
4334                            Ref::new("EqualsSegment").optional().to_matchable(),
4335                            Ref::new("ObjectReferenceSegment").to_matchable(),
4336                        ])
4337                        .to_matchable(),
4338                        Sequence::new(vec![
4339                            Ref::keyword("TEMPLATE").to_matchable(),
4340                            Ref::new("EqualsSegment").optional().to_matchable(),
4341                            Ref::new("ObjectReferenceSegment").to_matchable(),
4342                        ])
4343                        .to_matchable(),
4344                        Sequence::new(vec![
4345                            Ref::keyword("ENCODING").to_matchable(),
4346                            Ref::new("EqualsSegment").optional().to_matchable(),
4347                            one_of(vec![
4348                                Ref::new("QuotedLiteralSegment").to_matchable(),
4349                                Ref::keyword("DEFAULT").to_matchable(),
4350                            ])
4351                            .to_matchable(),
4352                        ])
4353                        .to_matchable(),
4354                        one_of(vec![
4355                            Sequence::new(vec![
4356                                Ref::keyword("LOCALE").to_matchable(),
4357                                Ref::new("EqualsSegment").optional().to_matchable(),
4358                                Ref::new("QuotedLiteralSegment").to_matchable(),
4359                            ])
4360                            .to_matchable(),
4361                            AnyNumberOf::new(vec![
4362                                Sequence::new(vec![
4363                                    Ref::keyword("LC_COLLATE").to_matchable(),
4364                                    Ref::new("EqualsSegment").optional().to_matchable(),
4365                                    Ref::new("QuotedLiteralSegment").to_matchable(),
4366                                ])
4367                                .to_matchable(),
4368                                Sequence::new(vec![
4369                                    Ref::keyword("LC_CTYPE").to_matchable(),
4370                                    Ref::new("EqualsSegment").optional().to_matchable(),
4371                                    Ref::new("QuotedLiteralSegment").to_matchable(),
4372                                ])
4373                                .to_matchable(),
4374                            ])
4375                            .to_matchable(),
4376                        ])
4377                        .to_matchable(),
4378                        Sequence::new(vec![
4379                            Ref::keyword("TABLESPACE").to_matchable(),
4380                            Ref::new("EqualsSegment").optional().to_matchable(),
4381                            one_of(vec![
4382                                Ref::new("TablespaceReferenceSegment").to_matchable(),
4383                                Ref::keyword("DEFAULT").to_matchable(),
4384                            ])
4385                            .to_matchable(),
4386                        ])
4387                        .to_matchable(),
4388                        Sequence::new(vec![
4389                            Ref::keyword("ALLOW_CONNECTIONS").to_matchable(),
4390                            Ref::new("EqualsSegment").optional().to_matchable(),
4391                            Ref::new("BooleanLiteralGrammar").to_matchable(),
4392                        ])
4393                        .to_matchable(),
4394                        Sequence::new(vec![
4395                            Ref::keyword("CONNECTION").to_matchable(),
4396                            Ref::keyword("LIMIT").to_matchable(),
4397                            Ref::new("EqualsSegment").optional().to_matchable(),
4398                            Ref::new("NumericLiteralSegment").to_matchable(),
4399                        ])
4400                        .to_matchable(),
4401                        Sequence::new(vec![
4402                            Ref::keyword("IS_TEMPLATE").to_matchable(),
4403                            Ref::new("EqualsSegment").optional().to_matchable(),
4404                            Ref::new("BooleanLiteralGrammar").to_matchable(),
4405                        ])
4406                        .to_matchable(),
4407                    ])
4408                    .to_matchable(),
4409                ])
4410                .to_matchable()
4411            })
4412            .to_matchable()
4413            .into(),
4414        ),
4415    ]);
4416
4417    postgres.add([(
4418        "AlterDatabaseStatementSegment".into(),
4419        NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_| {
4420            Sequence::new(vec![
4421                Ref::keyword("ALTER").to_matchable(),
4422                Ref::keyword("DATABASE").to_matchable(),
4423                Ref::new("DatabaseReferenceSegment").to_matchable(),
4424                one_of(vec![
4425                    Sequence::new(vec![
4426                        Ref::keyword("WITH").optional().to_matchable(),
4427                        AnyNumberOf::new(vec![
4428                            Sequence::new(vec![
4429                                Ref::keyword("ALLOW_CONNECTIONS").to_matchable(),
4430                                Ref::new("BooleanLiteralGrammar").to_matchable(),
4431                            ])
4432                            .to_matchable(),
4433                            Sequence::new(vec![
4434                                Ref::keyword("CONNECTION").to_matchable(),
4435                                Ref::keyword("LIMIT").to_matchable(),
4436                                Ref::new("NumericLiteralSegment").to_matchable(),
4437                            ])
4438                            .to_matchable(),
4439                            Sequence::new(vec![
4440                                Ref::keyword("IS_TEMPLATE").to_matchable(),
4441                                Ref::new("BooleanLiteralGrammar").to_matchable(),
4442                            ])
4443                            .to_matchable(),
4444                        ])
4445                        .config(|this| this.min_times(1))
4446                        .to_matchable(),
4447                    ])
4448                    .to_matchable(),
4449                    Sequence::new(vec![
4450                        Ref::keyword("RENAME").to_matchable(),
4451                        Ref::keyword("TO").to_matchable(),
4452                        Ref::new("DatabaseReferenceSegment").to_matchable(),
4453                    ])
4454                    .to_matchable(),
4455                    Sequence::new(vec![
4456                        Ref::keyword("OWNER").to_matchable(),
4457                        Ref::keyword("TO").to_matchable(),
4458                        one_of(vec![
4459                            Ref::new("ObjectReferenceSegment").to_matchable(),
4460                            Ref::keyword("CURRENT_ROLE").to_matchable(),
4461                            Ref::keyword("CURRENT_USER").to_matchable(),
4462                            Ref::keyword("SESSION_USER").to_matchable(),
4463                        ])
4464                        .to_matchable(),
4465                    ])
4466                    .to_matchable(),
4467                    Sequence::new(vec![
4468                        Ref::keyword("SET").to_matchable(),
4469                        Ref::keyword("TABLESPACE").to_matchable(),
4470                        Ref::new("TablespaceReferenceSegment").to_matchable(),
4471                    ])
4472                    .to_matchable(),
4473                    Sequence::new(vec![
4474                        Ref::keyword("SET").to_matchable(),
4475                        Ref::new("ParameterNameSegment").to_matchable(),
4476                        one_of(vec![
4477                            Sequence::new(vec![
4478                                one_of(vec![
4479                                    Ref::keyword("TO").to_matchable(),
4480                                    Ref::new("EqualsSegment").to_matchable(),
4481                                ])
4482                                .to_matchable(),
4483                                one_of(vec![
4484                                    Ref::keyword("DEFAULT").to_matchable(),
4485                                    Ref::new("LiteralGrammar").to_matchable(),
4486                                ])
4487                                .to_matchable(),
4488                            ])
4489                            .to_matchable(),
4490                            Sequence::new(vec![
4491                                Ref::keyword("FROM").to_matchable(),
4492                                Ref::keyword("CURRENT").to_matchable(),
4493                            ])
4494                            .to_matchable(),
4495                        ])
4496                        .to_matchable(),
4497                    ])
4498                    .to_matchable(),
4499                    Sequence::new(vec![
4500                        Ref::keyword("RESET").to_matchable(),
4501                        one_of(vec![
4502                            Ref::keyword("ALL").to_matchable(),
4503                            Ref::new("ParameterNameSegment").to_matchable(),
4504                        ])
4505                        .to_matchable(),
4506                    ])
4507                    .to_matchable(),
4508                ])
4509                .config(|this| this.optional())
4510                .to_matchable(),
4511            ])
4512            .to_matchable()
4513        })
4514        .to_matchable()
4515        .into(),
4516    )]);
4517
4518    postgres.replace_grammar(
4519        "DropDatabaseStatementSegment",
4520        Sequence::new(vec![
4521            Ref::keyword("DROP").to_matchable(),
4522            Ref::keyword("DATABASE").to_matchable(),
4523            Ref::new("IfExistsGrammar").optional().to_matchable(),
4524            Ref::new("DatabaseReferenceSegment").to_matchable(),
4525            Sequence::new(vec![
4526                Ref::keyword("WITH").optional().to_matchable(),
4527                Bracketed::new(vec![Ref::keyword("FORCE").to_matchable()]).to_matchable(),
4528            ])
4529            .config(|this| this.optional())
4530            .to_matchable(),
4531        ])
4532        .to_matchable(),
4533    );
4534
4535    postgres.add([
4536        (
4537            "VacuumStatementSegment".into(),
4538            NodeMatcher::new(SyntaxKind::VacuumStatement, |_| {
4539                Sequence::new(vec![
4540                    Ref::keyword("VACUUM").to_matchable(),
4541                    one_of(vec![
4542                        Sequence::new(vec![
4543                            Ref::keyword("FULL").optional().to_matchable(),
4544                            Ref::keyword("FREEZE").optional().to_matchable(),
4545                            Ref::keyword("VERBOSE").optional().to_matchable(),
4546                            one_of(vec![
4547                                Ref::keyword("ANALYZE").to_matchable(),
4548                                Ref::keyword("ANALYSE").to_matchable(),
4549                            ])
4550                            .config(|this| this.optional())
4551                            .to_matchable(),
4552                        ])
4553                        .to_matchable(),
4554                        Bracketed::new(vec![
4555                            Delimited::new(vec![
4556                                Sequence::new(vec![
4557                                    one_of(vec![
4558                                        Ref::keyword("FULL").to_matchable(),
4559                                        Ref::keyword("FREEZE").to_matchable(),
4560                                        Ref::keyword("VERBOSE").to_matchable(),
4561                                        Ref::keyword("ANALYZE").to_matchable(),
4562                                        Ref::keyword("ANALYSE").to_matchable(),
4563                                        Ref::keyword("DISABLE_PAGE_SKIPPING").to_matchable(),
4564                                        Ref::keyword("SKIP_LOCKED").to_matchable(),
4565                                        Ref::keyword("INDEX_CLEANUP").to_matchable(),
4566                                        Ref::keyword("PROCESS_TOAST").to_matchable(),
4567                                        Ref::keyword("TRUNCATE").to_matchable(),
4568                                        Ref::keyword("PARALLEL").to_matchable(),
4569                                    ])
4570                                    .to_matchable(),
4571                                    one_of(vec![
4572                                        Ref::new("LiteralGrammar").to_matchable(),
4573                                        Ref::new("NakedIdentifierSegment").to_matchable(),
4574                                        Ref::new("OnKeywordAsIdentifierSegment").to_matchable(),
4575                                    ])
4576                                    .config(|this| this.optional())
4577                                    .to_matchable(),
4578                                ])
4579                                .to_matchable(),
4580                            ])
4581                            .to_matchable(),
4582                        ])
4583                        .to_matchable(),
4584                    ])
4585                    .config(|this| this.optional())
4586                    .to_matchable(),
4587                    Delimited::new(vec![
4588                        Sequence::new(vec![
4589                            Ref::new("TableReferenceSegment").to_matchable(),
4590                            Ref::new("BracketedColumnReferenceListGrammar")
4591                                .optional()
4592                                .to_matchable(),
4593                        ])
4594                        .to_matchable(),
4595                    ])
4596                    .config(|this| this.optional())
4597                    .to_matchable(),
4598                ])
4599                .to_matchable()
4600            })
4601            .to_matchable()
4602            .into(),
4603        ),
4604        (
4605            "LikeOptionSegment".into(),
4606            NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_| {
4607                Sequence::new(vec![
4608                    one_of(vec![
4609                        Ref::keyword("INCLUDING").to_matchable(),
4610                        Ref::keyword("EXCLUDING").to_matchable(),
4611                    ])
4612                    .to_matchable(),
4613                    one_of(vec![
4614                        Ref::keyword("COMMENTS").to_matchable(),
4615                        Ref::keyword("CONSTRAINTS").to_matchable(),
4616                        Ref::keyword("DEFAULTS").to_matchable(),
4617                        Ref::keyword("GENERATED").to_matchable(),
4618                        Ref::keyword("IDENTITY").to_matchable(),
4619                        Ref::keyword("INDEXES").to_matchable(),
4620                        Ref::keyword("STATISTICS").to_matchable(),
4621                        Ref::keyword("STORAGE").to_matchable(),
4622                        Ref::keyword("ALL").to_matchable(),
4623                    ])
4624                    .to_matchable(),
4625                ])
4626                .to_matchable()
4627            })
4628            .to_matchable()
4629            .into(),
4630        ),
4631    ]);
4632
4633    postgres.replace_grammar(
4634        "ColumnConstraintSegment",
4635        Sequence::new(vec![
4636            Sequence::new(vec![
4637                Ref::keyword("CONSTRAINT").to_matchable(),
4638                Ref::new("ObjectReferenceSegment").to_matchable(),
4639            ])
4640            .config(|this| this.optional())
4641            .to_matchable(),
4642            one_of(vec![
4643                Sequence::new(vec![
4644                    Ref::keyword("NOT").optional().to_matchable(),
4645                    Ref::keyword("NULL").to_matchable(),
4646                ])
4647                .to_matchable(),
4648                Sequence::new(vec![
4649                    Ref::keyword("CHECK").to_matchable(),
4650                    Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4651                        .to_matchable(),
4652                    Sequence::new(vec![
4653                        Ref::keyword("NO").to_matchable(),
4654                        Ref::keyword("INHERIT").to_matchable(),
4655                    ])
4656                    .config(|this| this.optional())
4657                    .to_matchable(),
4658                ])
4659                .to_matchable(),
4660                Sequence::new(vec![
4661                    Ref::keyword("DEFAULT").to_matchable(),
4662                    one_of(vec![
4663                        Ref::new("ShorthandCastSegment").to_matchable(),
4664                        Ref::new("LiteralGrammar").to_matchable(),
4665                        Ref::new("FunctionSegment").to_matchable(),
4666                        Ref::new("BareFunctionSegment").to_matchable(),
4667                        Ref::new("ExpressionSegment").to_matchable(),
4668                    ])
4669                    .to_matchable(),
4670                ])
4671                .to_matchable(),
4672                Sequence::new(vec![
4673                    Ref::keyword("GENERATED").to_matchable(),
4674                    Ref::keyword("ALWAYS").to_matchable(),
4675                    Ref::keyword("AS").to_matchable(),
4676                    Ref::new("ExpressionSegment").to_matchable(),
4677                    Ref::keyword("STORED").to_matchable(),
4678                ])
4679                .to_matchable(),
4680                Sequence::new(vec![
4681                    Ref::keyword("GENERATED").to_matchable(),
4682                    one_of(vec![
4683                        Ref::keyword("ALWAYS").to_matchable(),
4684                        Sequence::new(vec![
4685                            Ref::keyword("BY").to_matchable(),
4686                            Ref::keyword("DEFAULT").to_matchable(),
4687                        ])
4688                        .to_matchable(),
4689                    ])
4690                    .to_matchable(),
4691                    Ref::keyword("AS").to_matchable(),
4692                    Ref::keyword("IDENTITY").to_matchable(),
4693                    Bracketed::new(vec![
4694                        AnyNumberOf::new(vec![
4695                            Ref::new("AlterSequenceOptionsSegment").to_matchable(),
4696                        ])
4697                        .to_matchable(),
4698                    ])
4699                    .config(|this| this.optional())
4700                    .to_matchable(),
4701                ])
4702                .to_matchable(),
4703                Sequence::new(vec![
4704                    Ref::keyword("UNIQUE").to_matchable(),
4705                    Sequence::new(vec![
4706                        Ref::keyword("NULLS").to_matchable(),
4707                        Ref::keyword("NOT").optional().to_matchable(),
4708                        Ref::keyword("DISTINCT").to_matchable(),
4709                    ])
4710                    .config(|this| this.optional())
4711                    .to_matchable(),
4712                    Sequence::new(vec![
4713                        Ref::keyword("WITH").to_matchable(),
4714                        Ref::new("DefinitionParametersSegment").to_matchable(),
4715                    ])
4716                    .config(|this| this.optional())
4717                    .to_matchable(),
4718                    Sequence::new(vec![
4719                        Ref::keyword("USING").to_matchable(),
4720                        Ref::keyword("INDEX").to_matchable(),
4721                        Ref::keyword("TABLESPACE").to_matchable(),
4722                        Ref::new("TablespaceReferenceSegment").to_matchable(),
4723                    ])
4724                    .config(|this| this.optional())
4725                    .to_matchable(),
4726                ])
4727                .to_matchable(),
4728                Sequence::new(vec![
4729                    Ref::keyword("PRIMARY").to_matchable(),
4730                    Ref::keyword("KEY").to_matchable(),
4731                    Sequence::new(vec![
4732                        Ref::keyword("WITH").to_matchable(),
4733                        Ref::new("DefinitionParametersSegment").to_matchable(),
4734                    ])
4735                    .config(|this| this.optional())
4736                    .to_matchable(),
4737                    Sequence::new(vec![
4738                        Ref::keyword("USING").to_matchable(),
4739                        Ref::keyword("INDEX").to_matchable(),
4740                        Ref::keyword("TABLESPACE").to_matchable(),
4741                        Ref::new("TablespaceReferenceSegment").to_matchable(),
4742                    ])
4743                    .config(|this| this.optional())
4744                    .to_matchable(),
4745                ])
4746                .to_matchable(),
4747                Ref::new("ReferenceDefinitionGrammar").to_matchable(),
4748            ])
4749            .to_matchable(),
4750            one_of(vec![
4751                Ref::keyword("DEFERRABLE").to_matchable(),
4752                Sequence::new(vec![
4753                    Ref::keyword("NOT").to_matchable(),
4754                    Ref::keyword("DEFERRABLE").to_matchable(),
4755                ])
4756                .to_matchable(),
4757            ])
4758            .config(|this| this.optional())
4759            .to_matchable(),
4760            one_of(vec![
4761                Sequence::new(vec![
4762                    Ref::keyword("INITIALLY").to_matchable(),
4763                    Ref::keyword("DEFERRED").to_matchable(),
4764                ])
4765                .to_matchable(),
4766                Sequence::new(vec![
4767                    Ref::keyword("INITIALLY").to_matchable(),
4768                    Ref::keyword("IMMEDIATE").to_matchable(),
4769                ])
4770                .to_matchable(),
4771            ])
4772            .config(|this| this.optional())
4773            .to_matchable(),
4774        ])
4775        .to_matchable(),
4776    );
4777
4778    postgres.add([(
4779        "PartitionBoundSpecSegment".into(),
4780        NodeMatcher::new(SyntaxKind::PartitionBoundSpec, |_| {
4781            one_of(vec![
4782                Sequence::new(vec![
4783                    Ref::keyword("IN").to_matchable(),
4784                    Bracketed::new(vec![
4785                        Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4786                            .to_matchable(),
4787                    ])
4788                    .to_matchable(),
4789                ])
4790                .to_matchable(),
4791                Sequence::new(vec![
4792                    Ref::keyword("FROM").to_matchable(),
4793                    Bracketed::new(vec![
4794                        Delimited::new(vec![
4795                            one_of(vec![
4796                                Ref::new("ExpressionSegment").to_matchable(),
4797                                Ref::keyword("MINVALUE").to_matchable(),
4798                                Ref::keyword("MAXVALUE").to_matchable(),
4799                            ])
4800                            .to_matchable(),
4801                        ])
4802                        .to_matchable(),
4803                    ])
4804                    .to_matchable(),
4805                    Ref::keyword("TO").to_matchable(),
4806                    Bracketed::new(vec![
4807                        Delimited::new(vec![
4808                            one_of(vec![
4809                                Ref::new("ExpressionSegment").to_matchable(),
4810                                Ref::keyword("MINVALUE").to_matchable(),
4811                                Ref::keyword("MAXVALUE").to_matchable(),
4812                            ])
4813                            .to_matchable(),
4814                        ])
4815                        .to_matchable(),
4816                    ])
4817                    .to_matchable(),
4818                ])
4819                .to_matchable(),
4820                Sequence::new(vec![
4821                    Ref::keyword("WITH").to_matchable(),
4822                    Bracketed::new(vec![
4823                        Sequence::new(vec![
4824                            Ref::keyword("MODULUS").to_matchable(),
4825                            Ref::new("NumericLiteralSegment").to_matchable(),
4826                            Ref::new("CommaSegment").to_matchable(),
4827                            Ref::keyword("REMAINDER").to_matchable(),
4828                            Ref::new("NumericLiteralSegment").to_matchable(),
4829                        ])
4830                        .to_matchable(),
4831                    ])
4832                    .to_matchable(),
4833                ])
4834                .to_matchable(),
4835            ])
4836            .to_matchable()
4837        })
4838        .to_matchable()
4839        .into(),
4840    )]);
4841
4842    postgres.add([(
4843        "TableConstraintSegment".into(),
4844        NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
4845            Sequence::new(vec![
4846                Sequence::new(vec![
4847                    Ref::keyword("CONSTRAINT").to_matchable(),
4848                    Ref::new("ObjectReferenceSegment").to_matchable(),
4849                ])
4850                .config(|this| this.optional())
4851                .to_matchable(),
4852                one_of(vec![
4853                    Sequence::new(vec![
4854                        Ref::keyword("CHECK").to_matchable(),
4855                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4856                            .to_matchable(),
4857                        Sequence::new(vec![
4858                            Ref::keyword("NO").to_matchable(),
4859                            Ref::keyword("INHERIT").to_matchable(),
4860                        ])
4861                        .config(|this| this.optional())
4862                        .to_matchable(),
4863                    ])
4864                    .to_matchable(),
4865                    Sequence::new(vec![
4866                        Ref::keyword("UNIQUE").to_matchable(),
4867                        Sequence::new(vec![
4868                            Ref::keyword("NULLS").to_matchable(),
4869                            Ref::keyword("NOT").optional().to_matchable(),
4870                            Ref::keyword("DISTINCT").to_matchable(),
4871                        ])
4872                        .config(|this| this.optional())
4873                        .to_matchable(),
4874                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
4875                        Ref::new("IndexParametersSegment").optional().to_matchable(),
4876                    ])
4877                    .to_matchable(),
4878                    Sequence::new(vec![
4879                        Ref::new("PrimaryKeyGrammar").to_matchable(),
4880                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
4881                        Ref::new("IndexParametersSegment").optional().to_matchable(),
4882                    ])
4883                    .to_matchable(),
4884                    Sequence::new(vec![
4885                        Ref::keyword("EXCLUDE").to_matchable(),
4886                        Sequence::new(vec![
4887                            Ref::keyword("USING").to_matchable(),
4888                            Ref::new("IndexAccessMethodSegment").to_matchable(),
4889                        ])
4890                        .config(|this| this.optional())
4891                        .to_matchable(),
4892                        Bracketed::new(vec![
4893                            Delimited::new(vec![
4894                                Ref::new("ExclusionConstraintElementSegment").to_matchable(),
4895                            ])
4896                            .to_matchable(),
4897                        ])
4898                        .to_matchable(),
4899                        Ref::new("IndexParametersSegment").optional().to_matchable(),
4900                        Sequence::new(vec![
4901                            Ref::keyword("WHERE").to_matchable(),
4902                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
4903                                .to_matchable(),
4904                        ])
4905                        .config(|this| this.optional())
4906                        .to_matchable(),
4907                    ])
4908                    .to_matchable(),
4909                    Sequence::new(vec![
4910                        Ref::keyword("FOREIGN").to_matchable(),
4911                        Ref::keyword("KEY").to_matchable(),
4912                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
4913                        Ref::new("ReferenceDefinitionGrammar").to_matchable(),
4914                    ])
4915                    .to_matchable(),
4916                ])
4917                .to_matchable(),
4918                AnyNumberOf::new(vec![
4919                    one_of(vec![
4920                        Ref::keyword("DEFERRABLE").to_matchable(),
4921                        Sequence::new(vec![
4922                            Ref::keyword("NOT").to_matchable(),
4923                            Ref::keyword("DEFERRABLE").to_matchable(),
4924                        ])
4925                        .to_matchable(),
4926                    ])
4927                    .to_matchable(),
4928                    one_of(vec![
4929                        Sequence::new(vec![
4930                            Ref::keyword("INITIALLY").to_matchable(),
4931                            Ref::keyword("DEFERRED").to_matchable(),
4932                        ])
4933                        .to_matchable(),
4934                        Sequence::new(vec![
4935                            Ref::keyword("INITIALLY").to_matchable(),
4936                            Ref::keyword("IMMEDIATE").to_matchable(),
4937                        ])
4938                        .to_matchable(),
4939                    ])
4940                    .to_matchable(),
4941                    Sequence::new(vec![
4942                        Ref::keyword("NOT").to_matchable(),
4943                        Ref::keyword("VALID").to_matchable(),
4944                    ])
4945                    .to_matchable(),
4946                    Sequence::new(vec![
4947                        Ref::keyword("NO").to_matchable(),
4948                        Ref::keyword("INHERIT").to_matchable(),
4949                    ])
4950                    .to_matchable(),
4951                ])
4952                .to_matchable(),
4953            ])
4954            .to_matchable()
4955        })
4956        .to_matchable()
4957        .into(),
4958    )]);
4959
4960    postgres.add([(
4961        "TableConstraintUsingIndexSegment".into(),
4962        NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
4963            Sequence::new(vec![
4964                Sequence::new(vec![
4965                    Ref::keyword("CONSTRAINT").to_matchable(),
4966                    Ref::new("ObjectReferenceSegment").to_matchable(),
4967                ])
4968                .config(|this| this.optional())
4969                .to_matchable(),
4970                Sequence::new(vec![
4971                    one_of(vec![
4972                        Ref::keyword("UNIQUE").to_matchable(),
4973                        Ref::new("PrimaryKeyGrammar").to_matchable(),
4974                    ])
4975                    .to_matchable(),
4976                    Ref::keyword("USING").to_matchable(),
4977                    Ref::keyword("INDEX").to_matchable(),
4978                    Ref::new("IndexReferenceSegment").to_matchable(),
4979                ])
4980                .to_matchable(),
4981                one_of(vec![
4982                    Ref::keyword("DEFERRABLE").to_matchable(),
4983                    Sequence::new(vec![
4984                        Ref::keyword("NOT").to_matchable(),
4985                        Ref::keyword("DEFERRABLE").to_matchable(),
4986                    ])
4987                    .to_matchable(),
4988                ])
4989                .config(|this| this.optional())
4990                .to_matchable(),
4991                one_of(vec![
4992                    Sequence::new(vec![
4993                        Ref::keyword("INITIALLY").to_matchable(),
4994                        Ref::keyword("DEFERRED").to_matchable(),
4995                    ])
4996                    .to_matchable(),
4997                    Sequence::new(vec![
4998                        Ref::keyword("INITIALLY").to_matchable(),
4999                        Ref::keyword("IMMEDIATE").to_matchable(),
5000                    ])
5001                    .to_matchable(),
5002                ])
5003                .config(|this| this.optional())
5004                .to_matchable(),
5005            ])
5006            .to_matchable()
5007        })
5008        .to_matchable()
5009        .into(),
5010    )]);
5011
5012    postgres.add([
5013        (
5014            "IndexParametersSegment".into(),
5015            NodeMatcher::new(SyntaxKind::IndexParameters, |_| {
5016                Sequence::new(vec![
5017                    Sequence::new(vec![
5018                        Ref::keyword("INCLUDE").to_matchable(),
5019                        Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
5020                    ])
5021                    .config(|this| this.optional())
5022                    .to_matchable(),
5023                    Sequence::new(vec![
5024                        Ref::keyword("WITH").to_matchable(),
5025                        Ref::new("DefinitionParametersSegment").to_matchable(),
5026                    ])
5027                    .config(|this| this.optional())
5028                    .to_matchable(),
5029                    Sequence::new(vec![
5030                        Ref::keyword("USING").to_matchable(),
5031                        Ref::keyword("INDEX").to_matchable(),
5032                        Ref::keyword("TABLESPACE").to_matchable(),
5033                        Ref::new("TablespaceReferenceSegment").to_matchable(),
5034                    ])
5035                    .config(|this| this.optional())
5036                    .to_matchable(),
5037                ])
5038                .to_matchable()
5039            })
5040            .to_matchable()
5041            .into(),
5042        ),
5043        (
5044            "ReferentialActionSegment".into(),
5045            NodeMatcher::new(SyntaxKind::ReferentialActionSegment, |_| {
5046                one_of(vec![
5047                    Ref::keyword("CASCADE").to_matchable(),
5048                    Sequence::new(vec![
5049                        Ref::keyword("SET").to_matchable(),
5050                        Ref::keyword("NULL").to_matchable(),
5051                    ])
5052                    .to_matchable(),
5053                    Sequence::new(vec![
5054                        Ref::keyword("SET").to_matchable(),
5055                        Ref::keyword("DEFAULT").to_matchable(),
5056                    ])
5057                    .to_matchable(),
5058                    Ref::keyword("RESTRICT").to_matchable(),
5059                    Sequence::new(vec![
5060                        Ref::keyword("NO").to_matchable(),
5061                        Ref::keyword("ACTION").to_matchable(),
5062                    ])
5063                    .to_matchable(),
5064                ])
5065                .to_matchable()
5066            })
5067            .to_matchable()
5068            .into(),
5069        ),
5070        (
5071            "IndexElementOptionsSegment".into(),
5072            NodeMatcher::new(SyntaxKind::IndexElementOptions, |_| {
5073                Sequence::new(vec![
5074                    Sequence::new(vec![
5075                        Ref::keyword("COLLATE").to_matchable(),
5076                        Ref::new("CollationReferenceSegment").to_matchable(),
5077                    ])
5078                    .config(|this| this.optional())
5079                    .to_matchable(),
5080                    Sequence::new(vec![
5081                        Ref::new("OperatorClassReferenceSegment")
5082                            .config(|this| {
5083                                this.exclude = Some(
5084                                    Sequence::new(vec![
5085                                        Ref::keyword("NULLS").to_matchable(),
5086                                        one_of(vec![
5087                                            Ref::keyword("FIRST").to_matchable(),
5088                                            Ref::keyword("LAST").to_matchable(),
5089                                        ])
5090                                        .to_matchable(),
5091                                    ])
5092                                    .to_matchable(),
5093                                );
5094                            })
5095                            .to_matchable(),
5096                        Ref::new("RelationOptionsSegment").optional().to_matchable(),
5097                    ])
5098                    .config(|this| this.optional())
5099                    .to_matchable(),
5100                    one_of(vec![
5101                        Ref::keyword("ASC").to_matchable(),
5102                        Ref::keyword("DESC").to_matchable(),
5103                    ])
5104                    .config(|this| this.optional())
5105                    .to_matchable(),
5106                    Sequence::new(vec![
5107                        Ref::keyword("NULLS").to_matchable(),
5108                        one_of(vec![
5109                            Ref::keyword("FIRST").to_matchable(),
5110                            Ref::keyword("LAST").to_matchable(),
5111                        ])
5112                        .to_matchable(),
5113                    ])
5114                    .config(|this| this.optional())
5115                    .to_matchable(),
5116                ])
5117                .to_matchable()
5118            })
5119            .to_matchable()
5120            .into(),
5121        ),
5122        (
5123            "IndexElementSegment".into(),
5124            NodeMatcher::new(SyntaxKind::IndexElement, |_| {
5125                Sequence::new(vec![
5126                    one_of(vec![
5127                        Ref::new("ColumnReferenceSegment").to_matchable(),
5128                        Ref::new("FunctionSegment").to_matchable(),
5129                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
5130                            .to_matchable(),
5131                    ])
5132                    .to_matchable(),
5133                    Ref::new("IndexElementOptionsSegment")
5134                        .optional()
5135                        .to_matchable(),
5136                ])
5137                .to_matchable()
5138            })
5139            .to_matchable()
5140            .into(),
5141        ),
5142        (
5143            "ExclusionConstraintElementSegment".into(),
5144            NodeMatcher::new(SyntaxKind::ExclusionConstraintElement, |_| {
5145                Sequence::new(vec![
5146                    Ref::new("IndexElementSegment").to_matchable(),
5147                    Ref::keyword("WITH").to_matchable(),
5148                    Ref::new("ComparisonOperatorGrammar").to_matchable(),
5149                ])
5150                .to_matchable()
5151            })
5152            .to_matchable()
5153            .into(),
5154        ),
5155        (
5156            "AlterDefaultPrivilegesStatementSegment".into(),
5157            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesStatement, |_| {
5158                Sequence::new(vec![
5159                    Ref::keyword("ALTER").to_matchable(),
5160                    Ref::keyword("DEFAULT").to_matchable(),
5161                    Ref::keyword("PRIVILEGES").to_matchable(),
5162                    Sequence::new(vec![
5163                        Ref::keyword("FOR").to_matchable(),
5164                        one_of(vec![
5165                            Ref::keyword("ROLE").to_matchable(),
5166                            Ref::keyword("USER").to_matchable(),
5167                        ])
5168                        .to_matchable(),
5169                        Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
5170                            .config(|this| {
5171                                this.terminators = vec![
5172                                    Ref::keyword("IN").to_matchable(),
5173                                    Ref::keyword("GRANT").to_matchable(),
5174                                    Ref::keyword("REVOKE").to_matchable(),
5175                                ];
5176                            })
5177                            .to_matchable(),
5178                    ])
5179                    .config(|this| this.optional())
5180                    .to_matchable(),
5181                    Sequence::new(vec![
5182                        Ref::keyword("IN").to_matchable(),
5183                        Ref::keyword("SCHEMA").to_matchable(),
5184                        Delimited::new(vec![Ref::new("SchemaReferenceSegment").to_matchable()])
5185                            .config(|this| {
5186                                this.terminators = vec![
5187                                    Ref::keyword("GRANT").to_matchable(),
5188                                    Ref::keyword("REVOKE").to_matchable(),
5189                                ];
5190                            })
5191                            .to_matchable(),
5192                    ])
5193                    .config(|this| this.optional())
5194                    .to_matchable(),
5195                    one_of(vec![
5196                        Ref::new("AlterDefaultPrivilegesGrantSegment").to_matchable(),
5197                        Ref::new("AlterDefaultPrivilegesRevokeSegment").to_matchable(),
5198                    ])
5199                    .to_matchable(),
5200                ])
5201                .to_matchable()
5202            })
5203            .to_matchable()
5204            .into(),
5205        ),
5206        (
5207            "AlterDefaultPrivilegesObjectPrivilegesSegment".into(),
5208            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesObjectPrivilege, |_| {
5209                one_of(vec![
5210                    Sequence::new(vec![
5211                        Ref::keyword("ALL").to_matchable(),
5212                        Ref::keyword("PRIVILEGES").optional().to_matchable(),
5213                    ])
5214                    .to_matchable(),
5215                    Delimited::new(vec![
5216                        Ref::keyword("CREATE").to_matchable(),
5217                        Ref::keyword("DELETE").to_matchable(),
5218                        Ref::keyword("EXECUTE").to_matchable(),
5219                        Ref::keyword("INSERT").to_matchable(),
5220                        Ref::keyword("REFERENCES").to_matchable(),
5221                        Ref::keyword("SELECT").to_matchable(),
5222                        Ref::keyword("TRIGGER").to_matchable(),
5223                        Ref::keyword("TRUNCATE").to_matchable(),
5224                        Ref::keyword("UPDATE").to_matchable(),
5225                        Ref::keyword("USAGE").to_matchable(),
5226                    ])
5227                    .config(|this| {
5228                        this.terminators = vec![Ref::keyword("ON").to_matchable()];
5229                    })
5230                    .to_matchable(),
5231                ])
5232                .to_matchable()
5233            })
5234            .to_matchable()
5235            .into(),
5236        ),
5237        (
5238            "AlterDefaultPrivilegesSchemaObjectsSegment".into(),
5239            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesSchemaObject, |_| {
5240                one_of(vec![
5241                    Ref::keyword("TABLES").to_matchable(),
5242                    Ref::keyword("FUNCTIONS").to_matchable(),
5243                    Ref::keyword("ROUTINES").to_matchable(),
5244                    Ref::keyword("SEQUENCES").to_matchable(),
5245                    Ref::keyword("TYPES").to_matchable(),
5246                    Ref::keyword("SCHEMAS").to_matchable(),
5247                ])
5248                .to_matchable()
5249            })
5250            .to_matchable()
5251            .into(),
5252        ),
5253        (
5254            "AlterDefaultPrivilegesToFromRolesSegment".into(),
5255            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesToFromRoles, |_| {
5256                one_of(vec![
5257                    Sequence::new(vec![
5258                        Ref::keyword("GROUP").optional().to_matchable(),
5259                        Ref::new("RoleReferenceSegment").to_matchable(),
5260                    ])
5261                    .to_matchable(),
5262                    Ref::keyword("PUBLIC").to_matchable(),
5263                ])
5264                .to_matchable()
5265            })
5266            .to_matchable()
5267            .into(),
5268        ),
5269        (
5270            "AlterDefaultPrivilegesGrantSegment".into(),
5271            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesGrant, |_| {
5272                Sequence::new(vec![
5273                    Ref::keyword("GRANT").to_matchable(),
5274                    Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(),
5275                    Ref::keyword("ON").to_matchable(),
5276                    Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(),
5277                    Ref::keyword("TO").to_matchable(),
5278                    Delimited::new(vec![
5279                        Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(),
5280                    ])
5281                    .config(|this| {
5282                        this.terminators = vec![Ref::keyword("WITH").to_matchable()];
5283                    })
5284                    .to_matchable(),
5285                    Sequence::new(vec![
5286                        Ref::keyword("WITH").to_matchable(),
5287                        Ref::keyword("GRANT").to_matchable(),
5288                        Ref::keyword("OPTION").to_matchable(),
5289                    ])
5290                    .config(|this| this.optional())
5291                    .to_matchable(),
5292                ])
5293                .to_matchable()
5294            })
5295            .to_matchable()
5296            .into(),
5297        ),
5298        (
5299            "AlterDefaultPrivilegesRevokeSegment".into(),
5300            NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesRevoke, |_| {
5301                Sequence::new(vec![
5302                    Ref::keyword("REVOKE").to_matchable(),
5303                    Sequence::new(vec![
5304                        Ref::keyword("GRANT").to_matchable(),
5305                        Ref::keyword("OPTION").to_matchable(),
5306                        Ref::keyword("FOR").to_matchable(),
5307                    ])
5308                    .config(|this| this.optional())
5309                    .to_matchable(),
5310                    Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(),
5311                    Ref::keyword("ON").to_matchable(),
5312                    Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(),
5313                    Ref::keyword("FROM").to_matchable(),
5314                    Delimited::new(vec![
5315                        Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(),
5316                    ])
5317                    .config(|this| {
5318                        this.terminators = vec![
5319                            Ref::keyword("RESTRICT").to_matchable(),
5320                            Ref::keyword("CASCADE").to_matchable(),
5321                        ];
5322                    })
5323                    .to_matchable(),
5324                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
5325                ])
5326                .to_matchable()
5327            })
5328            .to_matchable()
5329            .into(),
5330        ),
5331        (
5332            "DropOwnedStatementSegment".into(),
5333            NodeMatcher::new(SyntaxKind::DropOwnedStatement, |_| {
5334                Sequence::new(vec![
5335                    Ref::keyword("DROP").to_matchable(),
5336                    Ref::keyword("OWNED").to_matchable(),
5337                    Ref::keyword("BY").to_matchable(),
5338                    Delimited::new(vec![
5339                        one_of(vec![
5340                            Ref::keyword("CURRENT_ROLE").to_matchable(),
5341                            Ref::keyword("CURRENT_USER").to_matchable(),
5342                            Ref::keyword("SESSION_USER").to_matchable(),
5343                            Ref::new("RoleReferenceSegment").to_matchable(),
5344                        ])
5345                        .to_matchable(),
5346                    ])
5347                    .to_matchable(),
5348                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
5349                ])
5350                .to_matchable()
5351            })
5352            .to_matchable()
5353            .into(),
5354        ),
5355        (
5356            "ReassignOwnedStatementSegment".into(),
5357            NodeMatcher::new(SyntaxKind::ReassignOwnedStatement, |_| {
5358                Sequence::new(vec![
5359                    Ref::keyword("REASSIGN").to_matchable(),
5360                    Ref::keyword("OWNED").to_matchable(),
5361                    Ref::keyword("BY").to_matchable(),
5362                    Delimited::new(vec![
5363                        one_of(vec![
5364                            Ref::keyword("CURRENT_ROLE").to_matchable(),
5365                            Ref::keyword("CURRENT_USER").to_matchable(),
5366                            Ref::keyword("SESSION_USER").to_matchable(),
5367                            Ref::new("RoleReferenceSegment").to_matchable(),
5368                        ])
5369                        .to_matchable(),
5370                    ])
5371                    .to_matchable(),
5372                    Ref::keyword("TO").to_matchable(),
5373                    one_of(vec![
5374                        Ref::keyword("CURRENT_ROLE").to_matchable(),
5375                        Ref::keyword("CURRENT_USER").to_matchable(),
5376                        Ref::keyword("SESSION_USER").to_matchable(),
5377                        Ref::new("RoleReferenceSegment").to_matchable(),
5378                    ])
5379                    .to_matchable(),
5380                ])
5381                .to_matchable()
5382            })
5383            .to_matchable()
5384            .into(),
5385        ),
5386        (
5387            "CommentOnStatementSegment".into(),
5388            NodeMatcher::new(SyntaxKind::CommentClause, |_| {
5389                Sequence::new(vec![
5390                    Ref::keyword("COMMENT").to_matchable(),
5391                    Ref::keyword("ON").to_matchable(),
5392                    Sequence::new(vec![
5393                        one_of(vec![
5394                            Sequence::new(vec![
5395                                one_of(vec![
5396                                    Ref::keyword("TABLE").to_matchable(),
5397                                    Ref::keyword("VIEW").to_matchable(),
5398                                ])
5399                                .to_matchable(),
5400                                Ref::new("TableReferenceSegment").to_matchable(),
5401                            ])
5402                            .to_matchable(),
5403                            Sequence::new(vec![
5404                                Ref::keyword("CAST").to_matchable(),
5405                                Bracketed::new(vec![
5406                                    Sequence::new(vec![
5407                                        Ref::new("ObjectReferenceSegment").to_matchable(),
5408                                        Ref::keyword("AS").to_matchable(),
5409                                        Ref::new("ObjectReferenceSegment").to_matchable(),
5410                                    ])
5411                                    .to_matchable(),
5412                                ])
5413                                .to_matchable(),
5414                            ])
5415                            .to_matchable(),
5416                            Sequence::new(vec![
5417                                Ref::keyword("COLUMN").to_matchable(),
5418                                Ref::new("ColumnReferenceSegment").to_matchable(),
5419                            ])
5420                            .to_matchable(),
5421                            Sequence::new(vec![
5422                                Ref::keyword("CONSTRAINT").to_matchable(),
5423                                Ref::new("ObjectReferenceSegment").to_matchable(),
5424                                Sequence::new(vec![
5425                                    Ref::keyword("ON").to_matchable(),
5426                                    Ref::keyword("DOMAIN").optional().to_matchable(),
5427                                    Ref::new("ObjectReferenceSegment").to_matchable(),
5428                                ])
5429                                .to_matchable(),
5430                            ])
5431                            .to_matchable(),
5432                            Sequence::new(vec![
5433                                Ref::keyword("DATABASE").to_matchable(),
5434                                Ref::new("DatabaseReferenceSegment").to_matchable(),
5435                            ])
5436                            .to_matchable(),
5437                            Sequence::new(vec![
5438                                Ref::keyword("EXTENSION").to_matchable(),
5439                                Ref::new("ExtensionReferenceSegment").to_matchable(),
5440                            ])
5441                            .to_matchable(),
5442                            Sequence::new(vec![
5443                                Ref::keyword("FUNCTION").to_matchable(),
5444                                Ref::new("FunctionNameSegment").to_matchable(),
5445                                Sequence::new(vec![
5446                                    Ref::new("FunctionParameterListGrammar").to_matchable(),
5447                                ])
5448                                .config(|this| this.optional())
5449                                .to_matchable(),
5450                            ])
5451                            .to_matchable(),
5452                            Sequence::new(vec![
5453                                Ref::keyword("INDEX").to_matchable(),
5454                                Ref::new("IndexReferenceSegment").to_matchable(),
5455                            ])
5456                            .to_matchable(),
5457                            Sequence::new(vec![
5458                                Ref::keyword("SCHEMA").to_matchable(),
5459                                Ref::new("SchemaReferenceSegment").to_matchable(),
5460                            ])
5461                            .to_matchable(),
5462                            Sequence::new(vec![
5463                                one_of(vec![
5464                                    Ref::keyword("COLLATION").to_matchable(),
5465                                    Ref::keyword("CONVERSION").to_matchable(),
5466                                    Ref::keyword("DOMAIN").to_matchable(),
5467                                    Ref::keyword("LANGUAGE").to_matchable(),
5468                                    Ref::keyword("POLICY").to_matchable(),
5469                                    Ref::keyword("PUBLICATION").to_matchable(),
5470                                    Ref::keyword("ROLE").to_matchable(),
5471                                    Ref::keyword("RULE").to_matchable(),
5472                                    Ref::keyword("SEQUENCE").to_matchable(),
5473                                    Ref::keyword("SERVER").to_matchable(),
5474                                    Ref::keyword("STATISTICS").to_matchable(),
5475                                    Ref::keyword("SUBSCRIPTION").to_matchable(),
5476                                    Ref::keyword("TABLESPACE").to_matchable(),
5477                                    Ref::keyword("TRIGGER").to_matchable(),
5478                                    Ref::keyword("TYPE").to_matchable(),
5479                                    Sequence::new(vec![
5480                                        Ref::keyword("ACCESS").to_matchable(),
5481                                        Ref::keyword("METHOD").to_matchable(),
5482                                    ])
5483                                    .to_matchable(),
5484                                    Sequence::new(vec![
5485                                        Ref::keyword("EVENT").to_matchable(),
5486                                        Ref::keyword("TRIGGER").to_matchable(),
5487                                    ])
5488                                    .to_matchable(),
5489                                    Sequence::new(vec![
5490                                        Ref::keyword("FOREIGN").to_matchable(),
5491                                        Ref::keyword("DATA").to_matchable(),
5492                                        Ref::keyword("WRAPPER").to_matchable(),
5493                                    ])
5494                                    .to_matchable(),
5495                                    Sequence::new(vec![
5496                                        Ref::keyword("FOREIGN").to_matchable(),
5497                                        Ref::keyword("TABLE").to_matchable(),
5498                                    ])
5499                                    .to_matchable(),
5500                                    Sequence::new(vec![
5501                                        Ref::keyword("MATERIALIZED").to_matchable(),
5502                                        Ref::keyword("VIEW").to_matchable(),
5503                                    ])
5504                                    .to_matchable(),
5505                                    Sequence::new(vec![
5506                                        Ref::keyword("TEXT").to_matchable(),
5507                                        Ref::keyword("SEARCH").to_matchable(),
5508                                        Ref::keyword("CONFIGURATION").to_matchable(),
5509                                    ])
5510                                    .to_matchable(),
5511                                    Sequence::new(vec![
5512                                        Ref::keyword("TEXT").to_matchable(),
5513                                        Ref::keyword("SEARCH").to_matchable(),
5514                                        Ref::keyword("DICTIONARY").to_matchable(),
5515                                    ])
5516                                    .to_matchable(),
5517                                    Sequence::new(vec![
5518                                        Ref::keyword("TEXT").to_matchable(),
5519                                        Ref::keyword("SEARCH").to_matchable(),
5520                                        Ref::keyword("PARSER").to_matchable(),
5521                                    ])
5522                                    .to_matchable(),
5523                                    Sequence::new(vec![
5524                                        Ref::keyword("TEXT").to_matchable(),
5525                                        Ref::keyword("SEARCH").to_matchable(),
5526                                        Ref::keyword("TEMPLATE").to_matchable(),
5527                                    ])
5528                                    .to_matchable(),
5529                                ])
5530                                .to_matchable(),
5531                                Ref::new("ObjectReferenceSegment").to_matchable(),
5532                                Sequence::new(vec![
5533                                    Ref::keyword("ON").to_matchable(),
5534                                    Ref::new("ObjectReferenceSegment").to_matchable(),
5535                                ])
5536                                .config(|this| this.optional())
5537                                .to_matchable(),
5538                            ])
5539                            .to_matchable(),
5540                            Sequence::new(vec![
5541                                one_of(vec![
5542                                    Ref::keyword("AGGREGATE").to_matchable(),
5543                                    Ref::keyword("PROCEDURE").to_matchable(),
5544                                    Ref::keyword("ROUTINE").to_matchable(),
5545                                ])
5546                                .to_matchable(),
5547                                Ref::new("ObjectReferenceSegment").to_matchable(),
5548                                Bracketed::new(vec![
5549                                    Sequence::new(vec![Anything::new().to_matchable()])
5550                                        .config(|this| this.optional())
5551                                        .to_matchable(),
5552                                ])
5553                                .config(|this| this.optional())
5554                                .to_matchable(),
5555                            ])
5556                            .to_matchable(),
5557                        ])
5558                        .to_matchable(),
5559                        Sequence::new(vec![
5560                            Ref::keyword("IS").to_matchable(),
5561                            one_of(vec![
5562                                Ref::new("QuotedLiteralSegment").to_matchable(),
5563                                Ref::keyword("NULL").to_matchable(),
5564                            ])
5565                            .to_matchable(),
5566                        ])
5567                        .to_matchable(),
5568                    ])
5569                    .to_matchable(),
5570                ])
5571                .to_matchable()
5572            })
5573            .to_matchable()
5574            .into(),
5575        ),
5576    ]);
5577
5578    postgres.replace_grammar(
5579        "CreateIndexStatementSegment",
5580        Sequence::new(vec![
5581            Ref::keyword("CREATE").to_matchable(),
5582            Ref::keyword("UNIQUE").optional().to_matchable(),
5583            Ref::keyword("INDEX").to_matchable(),
5584            Ref::keyword("CONCURRENTLY").optional().to_matchable(),
5585            Sequence::new(vec![
5586                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
5587                Ref::new("IndexReferenceSegment").to_matchable(),
5588            ])
5589            .config(|this| this.optional())
5590            .to_matchable(),
5591            Ref::keyword("ON").to_matchable(),
5592            Ref::keyword("ONLY").optional().to_matchable(),
5593            Ref::new("TableReferenceSegment").to_matchable(),
5594            Sequence::new(vec![
5595                Ref::keyword("USING").to_matchable(),
5596                Ref::new("IndexAccessMethodSegment").to_matchable(),
5597            ])
5598            .config(|this| this.optional())
5599            .to_matchable(),
5600            Bracketed::new(vec![
5601                Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()]).to_matchable(),
5602            ])
5603            .to_matchable(),
5604            Sequence::new(vec![
5605                Ref::keyword("INCLUDE").to_matchable(),
5606                Bracketed::new(vec![
5607                    Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()])
5608                        .to_matchable(),
5609                ])
5610                .to_matchable(),
5611            ])
5612            .config(|this| this.optional())
5613            .to_matchable(),
5614            Sequence::new(vec![
5615                Ref::keyword("NULLS").to_matchable(),
5616                Ref::keyword("NOT").optional().to_matchable(),
5617                Ref::keyword("DISTINCT").to_matchable(),
5618            ])
5619            .config(|this| this.optional())
5620            .to_matchable(),
5621            Sequence::new(vec![
5622                Ref::keyword("WITH").to_matchable(),
5623                Ref::new("RelationOptionsSegment").to_matchable(),
5624            ])
5625            .config(|this| this.optional())
5626            .to_matchable(),
5627            Sequence::new(vec![
5628                Ref::keyword("TABLESPACE").to_matchable(),
5629                Ref::new("TablespaceReferenceSegment").to_matchable(),
5630            ])
5631            .config(|this| this.optional())
5632            .to_matchable(),
5633            Sequence::new(vec![
5634                Ref::keyword("WHERE").to_matchable(),
5635                Ref::new("ExpressionSegment").to_matchable(),
5636            ])
5637            .config(|this| this.optional())
5638            .to_matchable(),
5639        ])
5640        .to_matchable(),
5641    );
5642
5643    postgres.add([(
5644        "AlterIndexStatementSegment".into(),
5645        NodeMatcher::new(SyntaxKind::AlterIndexStatement, |_| {
5646            Sequence::new(vec![
5647                Ref::keyword("ALTER").to_matchable(),
5648                Ref::keyword("INDEX").to_matchable(),
5649                one_of(vec![
5650                    Sequence::new(vec![
5651                        Ref::new("IfExistsGrammar").optional().to_matchable(),
5652                        Ref::new("IndexReferenceSegment").to_matchable(),
5653                        one_of(vec![
5654                            Sequence::new(vec![
5655                                Ref::keyword("RENAME").to_matchable(),
5656                                Ref::keyword("TO").to_matchable(),
5657                                Ref::new("IndexReferenceSegment").to_matchable(),
5658                            ])
5659                            .to_matchable(),
5660                            Sequence::new(vec![
5661                                Ref::keyword("SET").to_matchable(),
5662                                Ref::keyword("TABLESPACE").to_matchable(),
5663                                Ref::new("TablespaceReferenceSegment").to_matchable(),
5664                            ])
5665                            .to_matchable(),
5666                            Sequence::new(vec![
5667                                Ref::keyword("ATTACH").to_matchable(),
5668                                Ref::keyword("PARTITION").to_matchable(),
5669                                Ref::new("IndexReferenceSegment").to_matchable(),
5670                            ])
5671                            .to_matchable(),
5672                            Sequence::new(vec![
5673                                Ref::keyword("NO").optional().to_matchable(),
5674                                Ref::keyword("DEPENDS").to_matchable(),
5675                                Ref::keyword("ON").to_matchable(),
5676                                Ref::keyword("EXTENSION").to_matchable(),
5677                                Ref::new("ExtensionReferenceSegment").to_matchable(),
5678                            ])
5679                            .to_matchable(),
5680                            Sequence::new(vec![
5681                                Ref::keyword("SET").to_matchable(),
5682                                Bracketed::new(vec![
5683                                    Delimited::new(vec![
5684                                        Sequence::new(vec![
5685                                            Ref::new("ParameterNameSegment").to_matchable(),
5686                                            Sequence::new(vec![
5687                                                Ref::new("EqualsSegment").to_matchable(),
5688                                                Ref::new("LiteralGrammar").to_matchable(),
5689                                            ])
5690                                            .config(|this| this.optional())
5691                                            .to_matchable(),
5692                                        ])
5693                                        .to_matchable(),
5694                                    ])
5695                                    .to_matchable(),
5696                                ])
5697                                .to_matchable(),
5698                            ])
5699                            .to_matchable(),
5700                            Sequence::new(vec![
5701                                Ref::keyword("RESET").to_matchable(),
5702                                Bracketed::new(vec![
5703                                    Delimited::new(vec![
5704                                        Ref::new("ParameterNameSegment").to_matchable(),
5705                                    ])
5706                                    .to_matchable(),
5707                                ])
5708                                .to_matchable(),
5709                            ])
5710                            .to_matchable(),
5711                            Sequence::new(vec![
5712                                Ref::keyword("ALTER").to_matchable(),
5713                                Ref::keyword("COLUMN").optional().to_matchable(),
5714                                Ref::new("NumericLiteralSegment").to_matchable(),
5715                                Ref::keyword("SET").to_matchable(),
5716                                Ref::keyword("STATISTICS").to_matchable(),
5717                                Ref::new("NumericLiteralSegment").to_matchable(),
5718                            ])
5719                            .to_matchable(),
5720                        ])
5721                        .to_matchable(),
5722                    ])
5723                    .to_matchable(),
5724                    Sequence::new(vec![
5725                        Ref::keyword("ALL").to_matchable(),
5726                        Ref::keyword("IN").to_matchable(),
5727                        Ref::keyword("TABLESPACE").to_matchable(),
5728                        Ref::new("TablespaceReferenceSegment").to_matchable(),
5729                        Sequence::new(vec![
5730                            Ref::keyword("OWNED").to_matchable(),
5731                            Ref::keyword("BY").to_matchable(),
5732                            Delimited::new(vec![Ref::new("RoleReferenceSegment").to_matchable()])
5733                                .to_matchable(),
5734                        ])
5735                        .config(|this| this.optional())
5736                        .to_matchable(),
5737                        Ref::keyword("SET").to_matchable(),
5738                        Ref::keyword("TABLESPACE").to_matchable(),
5739                        Ref::new("TablespaceReferenceSegment").to_matchable(),
5740                        Ref::keyword("NOWAIT").optional().to_matchable(),
5741                    ])
5742                    .to_matchable(),
5743                ])
5744                .to_matchable(),
5745            ])
5746            .to_matchable()
5747        })
5748        .to_matchable()
5749        .into(),
5750    )]);
5751
5752    postgres.add([(
5753        "ReindexStatementSegment".into(),
5754        NodeMatcher::new(SyntaxKind::ReindexStatementSegment, |_| {
5755            Sequence::new(vec![
5756                Ref::keyword("REINDEX").to_matchable(),
5757                Bracketed::new(vec![
5758                    Delimited::new(vec![
5759                        Sequence::new(vec![
5760                            Ref::keyword("CONCURRENTLY").to_matchable(),
5761                            Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
5762                        ])
5763                        .to_matchable(),
5764                        Sequence::new(vec![
5765                            Ref::keyword("TABLESPACE").to_matchable(),
5766                            Ref::new("TablespaceReferenceSegment").to_matchable(),
5767                        ])
5768                        .to_matchable(),
5769                        Sequence::new(vec![
5770                            Ref::keyword("VERBOSE").to_matchable(),
5771                            Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
5772                        ])
5773                        .to_matchable(),
5774                    ])
5775                    .to_matchable(),
5776                ])
5777                .config(|this| this.optional())
5778                .to_matchable(),
5779                one_of(vec![
5780                    Sequence::new(vec![
5781                        Ref::keyword("INDEX").to_matchable(),
5782                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
5783                        Ref::new("IndexReferenceSegment").to_matchable(),
5784                    ])
5785                    .to_matchable(),
5786                    Sequence::new(vec![
5787                        Ref::keyword("TABLE").to_matchable(),
5788                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
5789                        Ref::new("TableReferenceSegment").to_matchable(),
5790                    ])
5791                    .to_matchable(),
5792                    Sequence::new(vec![
5793                        Ref::keyword("SCHEMA").to_matchable(),
5794                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
5795                        Ref::new("SchemaReferenceSegment").to_matchable(),
5796                    ])
5797                    .to_matchable(),
5798                    Sequence::new(vec![
5799                        one_of(vec![
5800                            Ref::keyword("DATABASE").to_matchable(),
5801                            Ref::keyword("SYSTEM").to_matchable(),
5802                        ])
5803                        .to_matchable(),
5804                        Ref::keyword("CONCURRENTLY").optional().to_matchable(),
5805                        Ref::new("DatabaseReferenceSegment").to_matchable(),
5806                    ])
5807                    .to_matchable(),
5808                ])
5809                .to_matchable(),
5810            ])
5811            .to_matchable()
5812        })
5813        .to_matchable()
5814        .into(),
5815    )]);
5816
5817    postgres.replace_grammar(
5818        "DropIndexStatementSegment",
5819        Sequence::new(vec![
5820            Ref::keyword("DROP").to_matchable(),
5821            Ref::keyword("INDEX").to_matchable(),
5822            Ref::keyword("CONCURRENTLY").optional().to_matchable(),
5823            Ref::new("IfExistsGrammar").optional().to_matchable(),
5824            Delimited::new(vec![Ref::new("IndexReferenceSegment").to_matchable()]).to_matchable(),
5825            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
5826        ])
5827        .to_matchable(),
5828    );
5829
5830    postgres.replace_grammar(
5831        "FrameClauseSegment",
5832        {
5833            let frame_extent = ansi::frame_extent();
5834
5835            let frame_exclusion = Sequence::new(vec![
5836                Ref::keyword("EXCLUDE").to_matchable(),
5837                one_of(vec![
5838                    Sequence::new(vec![
5839                        Ref::keyword("CURRENT").to_matchable(),
5840                        Ref::keyword("ROW").to_matchable(),
5841                    ])
5842                    .to_matchable(),
5843                    Ref::keyword("GROUP").to_matchable(),
5844                    Ref::keyword("TIES").to_matchable(),
5845                    Sequence::new(vec![
5846                        Ref::keyword("NO").to_matchable(),
5847                        Ref::keyword("OTHERS").to_matchable(),
5848                    ])
5849                    .to_matchable(),
5850                ])
5851                .to_matchable(),
5852            ])
5853            .config(|this| this.optional());
5854
5855            Sequence::new(vec![
5856                Ref::new("FrameClauseUnitGrammar").to_matchable(),
5857                one_of(vec![
5858                    frame_extent.clone().to_matchable(),
5859                    Sequence::new(vec![
5860                        Ref::keyword("BETWEEN").to_matchable(),
5861                        frame_extent.clone().to_matchable(),
5862                        Ref::keyword("AND").to_matchable(),
5863                        frame_extent.clone().to_matchable(),
5864                    ])
5865                    .to_matchable(),
5866                ])
5867                .to_matchable(),
5868                frame_exclusion.to_matchable(),
5869            ])
5870        }
5871        .to_matchable(),
5872    );
5873
5874    postgres.replace_grammar(
5875        "CreateSequenceOptionsSegment",
5876        one_of(vec![
5877            Sequence::new(vec![
5878                Ref::keyword("AS").to_matchable(),
5879                Ref::new("DatatypeSegment").to_matchable(),
5880            ])
5881            .to_matchable(),
5882            Sequence::new(vec![
5883                Ref::keyword("INCREMENT").to_matchable(),
5884                Ref::keyword("BY").optional().to_matchable(),
5885                Ref::new("NumericLiteralSegment").to_matchable(),
5886            ])
5887            .to_matchable(),
5888            one_of(vec![
5889                Sequence::new(vec![
5890                    Ref::keyword("MINVALUE").to_matchable(),
5891                    Ref::new("NumericLiteralSegment").to_matchable(),
5892                ])
5893                .to_matchable(),
5894                Sequence::new(vec![
5895                    Ref::keyword("NO").to_matchable(),
5896                    Ref::keyword("MINVALUE").to_matchable(),
5897                ])
5898                .to_matchable(),
5899            ])
5900            .to_matchable(),
5901            one_of(vec![
5902                Sequence::new(vec![
5903                    Ref::keyword("MAXVALUE").to_matchable(),
5904                    Ref::new("NumericLiteralSegment").to_matchable(),
5905                ])
5906                .to_matchable(),
5907                Sequence::new(vec![
5908                    Ref::keyword("NO").to_matchable(),
5909                    Ref::keyword("MAXVALUE").to_matchable(),
5910                ])
5911                .to_matchable(),
5912            ])
5913            .to_matchable(),
5914            Sequence::new(vec![
5915                Ref::keyword("START").to_matchable(),
5916                Ref::keyword("WITH").optional().to_matchable(),
5917                Ref::new("NumericLiteralSegment").to_matchable(),
5918            ])
5919            .to_matchable(),
5920            Sequence::new(vec![
5921                Ref::keyword("CACHE").to_matchable(),
5922                Ref::new("NumericLiteralSegment").to_matchable(),
5923            ])
5924            .to_matchable(),
5925            one_of(vec![
5926                Ref::keyword("CYCLE").to_matchable(),
5927                Sequence::new(vec![
5928                    Ref::keyword("NO").to_matchable(),
5929                    Ref::keyword("CYCLE").to_matchable(),
5930                ])
5931                .to_matchable(),
5932            ])
5933            .to_matchable(),
5934            Sequence::new(vec![
5935                Ref::keyword("OWNED").to_matchable(),
5936                Ref::keyword("BY").to_matchable(),
5937                one_of(vec![
5938                    Ref::keyword("NONE").to_matchable(),
5939                    Ref::new("ColumnReferenceSegment").to_matchable(),
5940                ])
5941                .to_matchable(),
5942            ])
5943            .to_matchable(),
5944        ])
5945        .to_matchable(),
5946    );
5947
5948    postgres.add([(
5949        "CreateSequenceStatementSegment".into(),
5950        NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_| {
5951            Sequence::new(vec![
5952                Ref::keyword("CREATE").to_matchable(),
5953                Ref::new("TemporaryGrammar").optional().to_matchable(),
5954                Ref::keyword("SEQUENCE").to_matchable(),
5955                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
5956                Ref::new("SequenceReferenceSegment").to_matchable(),
5957                AnyNumberOf::new(vec![
5958                    Ref::new("CreateSequenceOptionsSegment").to_matchable(),
5959                ])
5960                .config(|this| this.optional())
5961                .to_matchable(),
5962            ])
5963            .to_matchable()
5964        })
5965        .to_matchable()
5966        .into(),
5967    )]);
5968
5969    postgres.replace_grammar(
5970        "AlterSequenceOptionsSegment",
5971        one_of(vec![
5972            Sequence::new(vec![
5973                Ref::keyword("AS").to_matchable(),
5974                Ref::new("DatatypeSegment").to_matchable(),
5975            ])
5976            .to_matchable(),
5977            Sequence::new(vec![
5978                Ref::keyword("INCREMENT").to_matchable(),
5979                Ref::keyword("BY").optional().to_matchable(),
5980                Ref::new("NumericLiteralSegment").to_matchable(),
5981            ])
5982            .to_matchable(),
5983            one_of(vec![
5984                Sequence::new(vec![
5985                    Ref::keyword("MINVALUE").to_matchable(),
5986                    Ref::new("NumericLiteralSegment").to_matchable(),
5987                ])
5988                .to_matchable(),
5989                Sequence::new(vec![
5990                    Ref::keyword("NO").to_matchable(),
5991                    Ref::keyword("MINVALUE").to_matchable(),
5992                ])
5993                .to_matchable(),
5994            ])
5995            .to_matchable(),
5996            one_of(vec![
5997                Sequence::new(vec![
5998                    Ref::keyword("MAXVALUE").to_matchable(),
5999                    Ref::new("NumericLiteralSegment").to_matchable(),
6000                ])
6001                .to_matchable(),
6002                Sequence::new(vec![
6003                    Ref::keyword("NO").to_matchable(),
6004                    Ref::keyword("MAXVALUE").to_matchable(),
6005                ])
6006                .to_matchable(),
6007            ])
6008            .to_matchable(),
6009            Sequence::new(vec![
6010                Ref::keyword("SEQUENCE").to_matchable(),
6011                Ref::keyword("NAME").to_matchable(),
6012                Ref::new("SequenceReferenceSegment").to_matchable(),
6013            ])
6014            .to_matchable(),
6015            Sequence::new(vec![
6016                Ref::keyword("START").to_matchable(),
6017                Ref::keyword("WITH").optional().to_matchable(),
6018                Ref::new("NumericLiteralSegment").to_matchable(),
6019            ])
6020            .to_matchable(),
6021            Sequence::new(vec![
6022                Ref::keyword("RESTART").to_matchable(),
6023                Ref::keyword("WITH").optional().to_matchable(),
6024                Ref::new("NumericLiteralSegment").to_matchable(),
6025            ])
6026            .to_matchable(),
6027            Sequence::new(vec![
6028                Ref::keyword("CACHE").to_matchable(),
6029                Ref::new("NumericLiteralSegment").to_matchable(),
6030            ])
6031            .to_matchable(),
6032            Sequence::new(vec![
6033                Ref::keyword("NO").optional().to_matchable(),
6034                Ref::keyword("CYCLE").to_matchable(),
6035            ])
6036            .to_matchable(),
6037            Sequence::new(vec![
6038                Ref::keyword("OWNED").to_matchable(),
6039                Ref::keyword("BY").to_matchable(),
6040                one_of(vec![
6041                    Ref::keyword("NONE").to_matchable(),
6042                    Ref::new("ColumnReferenceSegment").to_matchable(),
6043                ])
6044                .to_matchable(),
6045            ])
6046            .to_matchable(),
6047        ])
6048        .to_matchable(),
6049    );
6050
6051    postgres.replace_grammar(
6052        "AlterSequenceStatementSegment",
6053        Sequence::new(vec![
6054            Ref::keyword("ALTER").to_matchable(),
6055            Ref::keyword("SEQUENCE").to_matchable(),
6056            Ref::new("IfExistsGrammar").optional().to_matchable(),
6057            Ref::new("SequenceReferenceSegment").to_matchable(),
6058            one_of(vec![
6059                AnyNumberOf::new(vec![Ref::new("AlterSequenceOptionsSegment").to_matchable()])
6060                    .config(|this| this.optional())
6061                    .to_matchable(),
6062                Sequence::new(vec![
6063                    Ref::keyword("OWNER").to_matchable(),
6064                    Ref::keyword("TO").to_matchable(),
6065                    one_of(vec![
6066                        Ref::new("ParameterNameSegment").to_matchable(),
6067                        Ref::keyword("CURRENT_USER").to_matchable(),
6068                        Ref::keyword("SESSION_USER").to_matchable(),
6069                    ])
6070                    .to_matchable(),
6071                ])
6072                .to_matchable(),
6073                Sequence::new(vec![
6074                    Ref::keyword("RENAME").to_matchable(),
6075                    Ref::keyword("TO").to_matchable(),
6076                    Ref::new("SequenceReferenceSegment").to_matchable(),
6077                ])
6078                .to_matchable(),
6079                Sequence::new(vec![
6080                    Ref::keyword("SET").to_matchable(),
6081                    Ref::keyword("SCHEMA").to_matchable(),
6082                    Ref::new("SchemaReferenceSegment").to_matchable(),
6083                ])
6084                .to_matchable(),
6085            ])
6086            .to_matchable(),
6087        ])
6088        .to_matchable(),
6089    );
6090
6091    postgres.replace_grammar(
6092        "DropSequenceStatementSegment",
6093        Sequence::new(vec![
6094            Ref::keyword("DROP").to_matchable(),
6095            Ref::keyword("SEQUENCE").to_matchable(),
6096            Ref::new("IfExistsGrammar").optional().to_matchable(),
6097            Delimited::new(vec![Ref::new("SequenceReferenceSegment").to_matchable()])
6098                .to_matchable(),
6099            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
6100        ])
6101        .to_matchable(),
6102    );
6103
6104    postgres.add([(
6105        "AnalyzeStatementSegment".into(),
6106        NodeMatcher::new(SyntaxKind::AnalyzeStatement, |_| {
6107            {
6108                let option = Sequence::new(vec![
6109                    one_of(vec![
6110                        Ref::keyword("VERBOSE").to_matchable(),
6111                        Ref::keyword("SKIP_LOCKED").to_matchable(),
6112                    ])
6113                    .to_matchable(),
6114                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
6115                ]);
6116
6117                let tables_and_columns = Sequence::new(vec![
6118                    Ref::new("TableReferenceSegment").to_matchable(),
6119                    Bracketed::new(vec![
6120                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
6121                            .to_matchable(),
6122                    ])
6123                    .config(|this| this.optional())
6124                    .to_matchable(),
6125                ]);
6126
6127                Sequence::new(vec![
6128                    one_of(vec![
6129                        Ref::keyword("ANALYZE").to_matchable(),
6130                        Ref::keyword("ANALYSE").to_matchable(),
6131                    ])
6132                    .to_matchable(),
6133                    one_of(vec![
6134                        Bracketed::new(vec![
6135                            Delimited::new(vec![option.to_matchable()]).to_matchable(),
6136                        ])
6137                        .to_matchable(),
6138                        Ref::keyword("VERBOSE").to_matchable(),
6139                    ])
6140                    .config(|this| this.optional())
6141                    .to_matchable(),
6142                    Delimited::new(vec![tables_and_columns.to_matchable()])
6143                        .config(|this| this.optional())
6144                        .to_matchable(),
6145                ])
6146            }
6147            .to_matchable()
6148        })
6149        .to_matchable()
6150        .into(),
6151    )]);
6152
6153    postgres.replace_grammar("StatementSegment", statement_segment());
6154
6155    postgres.replace_grammar(
6156        "CreateTriggerStatementSegment",
6157        Sequence::new(vec![
6158            Ref::keyword("CREATE").to_matchable(),
6159            Sequence::new(vec![
6160                Ref::keyword("OR").to_matchable(),
6161                Ref::keyword("REPLACE").to_matchable(),
6162            ])
6163            .config(|this| this.optional())
6164            .to_matchable(),
6165            Ref::keyword("CONSTRAINT").optional().to_matchable(),
6166            Ref::keyword("TRIGGER").to_matchable(),
6167            Ref::new("TriggerReferenceSegment").to_matchable(),
6168            one_of(vec![
6169                Ref::keyword("BEFORE").to_matchable(),
6170                Ref::keyword("AFTER").to_matchable(),
6171                Sequence::new(vec![
6172                    Ref::keyword("INSTEAD").to_matchable(),
6173                    Ref::keyword("OF").to_matchable(),
6174                ])
6175                .to_matchable(),
6176            ])
6177            .to_matchable(),
6178            Delimited::new(vec![
6179                Ref::keyword("INSERT").to_matchable(),
6180                Ref::keyword("DELETE").to_matchable(),
6181                Ref::keyword("TRUNCATE").to_matchable(),
6182                Sequence::new(vec![
6183                    Ref::keyword("UPDATE").to_matchable(),
6184                    Sequence::new(vec![
6185                        Ref::keyword("OF").to_matchable(),
6186                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
6187                            .config(|this| {
6188                                this.terminators = vec![
6189                                    Ref::keyword("OR").to_matchable(),
6190                                    Ref::keyword("ON").to_matchable(),
6191                                ];
6192                                this.optional();
6193                            })
6194                            .to_matchable(),
6195                    ])
6196                    .config(|this| this.optional())
6197                    .to_matchable(),
6198                ])
6199                .to_matchable(),
6200            ])
6201            .config(|this| this.delimiter(Ref::keyword("OR")))
6202            .to_matchable(),
6203            Ref::keyword("ON").to_matchable(),
6204            Ref::new("TableReferenceSegment").to_matchable(),
6205            AnyNumberOf::new(vec![
6206                Sequence::new(vec![
6207                    Ref::keyword("FROM").to_matchable(),
6208                    Ref::new("TableReferenceSegment").to_matchable(),
6209                ])
6210                .to_matchable(),
6211                one_of(vec![
6212                    Sequence::new(vec![
6213                        Ref::keyword("NOT").to_matchable(),
6214                        Ref::keyword("DEFERRABLE").to_matchable(),
6215                    ])
6216                    .to_matchable(),
6217                    Sequence::new(vec![
6218                        Ref::keyword("DEFERRABLE").optional().to_matchable(),
6219                        one_of(vec![
6220                            Sequence::new(vec![
6221                                Ref::keyword("INITIALLY").to_matchable(),
6222                                Ref::keyword("IMMEDIATE").to_matchable(),
6223                            ])
6224                            .to_matchable(),
6225                            Sequence::new(vec![
6226                                Ref::keyword("INITIALLY").to_matchable(),
6227                                Ref::keyword("DEFERRED").to_matchable(),
6228                            ])
6229                            .to_matchable(),
6230                        ])
6231                        .to_matchable(),
6232                    ])
6233                    .to_matchable(),
6234                ])
6235                .to_matchable(),
6236                Sequence::new(vec![
6237                    Ref::keyword("REFERENCING").to_matchable(),
6238                    one_of(vec![
6239                        Ref::keyword("OLD").to_matchable(),
6240                        Ref::keyword("NEW").to_matchable(),
6241                    ])
6242                    .to_matchable(),
6243                    Ref::keyword("TABLE").to_matchable(),
6244                    Ref::keyword("AS").to_matchable(),
6245                    Ref::new("TableReferenceSegment").to_matchable(),
6246                    Sequence::new(vec![
6247                        one_of(vec![
6248                            Ref::keyword("OLD").to_matchable(),
6249                            Ref::keyword("NEW").to_matchable(),
6250                        ])
6251                        .to_matchable(),
6252                        Ref::keyword("TABLE").to_matchable(),
6253                        Ref::keyword("AS").to_matchable(),
6254                        Ref::new("TableReferenceSegment").to_matchable(),
6255                    ])
6256                    .config(|this| this.optional())
6257                    .to_matchable(),
6258                ])
6259                .to_matchable(),
6260                Sequence::new(vec![
6261                    Ref::keyword("FOR").to_matchable(),
6262                    Ref::keyword("EACH").optional().to_matchable(),
6263                    one_of(vec![
6264                        Ref::keyword("ROW").to_matchable(),
6265                        Ref::keyword("STATEMENT").to_matchable(),
6266                    ])
6267                    .to_matchable(),
6268                ])
6269                .to_matchable(),
6270                Sequence::new(vec![
6271                    Ref::keyword("WHEN").to_matchable(),
6272                    Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
6273                        .to_matchable(),
6274                ])
6275                .to_matchable(),
6276            ])
6277            .to_matchable(),
6278            Sequence::new(vec![
6279                Ref::keyword("EXECUTE").to_matchable(),
6280                one_of(vec![
6281                    Ref::keyword("FUNCTION").to_matchable(),
6282                    Ref::keyword("PROCEDURE").to_matchable(),
6283                ])
6284                .to_matchable(),
6285                Ref::new("FunctionSegment").to_matchable(),
6286            ])
6287            .to_matchable(),
6288        ])
6289        .to_matchable(),
6290    );
6291
6292    postgres.add([(
6293        "AlterTriggerStatementSegment".into(),
6294        NodeMatcher::new(SyntaxKind::AlterTrigger, |_| {
6295            Sequence::new(vec![
6296                Ref::keyword("ALTER").to_matchable(),
6297                Ref::keyword("TRIGGER").to_matchable(),
6298                Ref::new("TriggerReferenceSegment").to_matchable(),
6299                Ref::keyword("ON").to_matchable(),
6300                Ref::new("TableReferenceSegment").to_matchable(),
6301                one_of(vec![
6302                    Sequence::new(vec![
6303                        Ref::keyword("RENAME").to_matchable(),
6304                        Ref::keyword("TO").to_matchable(),
6305                        Ref::new("TriggerReferenceSegment").to_matchable(),
6306                    ])
6307                    .to_matchable(),
6308                    Sequence::new(vec![
6309                        Ref::keyword("NO").optional().to_matchable(),
6310                        Ref::keyword("DEPENDS").to_matchable(),
6311                        Ref::keyword("ON").to_matchable(),
6312                        Ref::keyword("EXTENSION").to_matchable(),
6313                        Ref::new("ExtensionReferenceSegment").to_matchable(),
6314                    ])
6315                    .to_matchable(),
6316                ])
6317                .to_matchable(),
6318            ])
6319            .to_matchable()
6320        })
6321        .to_matchable()
6322        .into(),
6323    )]);
6324
6325    postgres.replace_grammar(
6326        "DropTriggerStatementSegment",
6327        Sequence::new(vec![
6328            Ref::keyword("DROP").to_matchable(),
6329            Ref::keyword("TRIGGER").to_matchable(),
6330            Ref::new("IfExistsGrammar").optional().to_matchable(),
6331            Ref::new("TriggerReferenceSegment").to_matchable(),
6332            Ref::keyword("ON").to_matchable(),
6333            Ref::new("TableReferenceSegment").to_matchable(),
6334            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
6335        ])
6336        .to_matchable(),
6337    );
6338
6339    postgres.replace_grammar(
6340        "AliasExpressionSegment",
6341        Sequence::new(vec![
6342            Ref::keyword("AS").optional().to_matchable(),
6343            one_of(vec![
6344                Sequence::new(vec![
6345                    Ref::new("SingleIdentifierGrammar").to_matchable(),
6346                    Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()])
6347                        .config(|this| this.optional())
6348                        .to_matchable(),
6349                ])
6350                .to_matchable(),
6351                Sequence::new(vec![
6352                    Ref::new("SingleIdentifierGrammar")
6353                        .optional()
6354                        .to_matchable(),
6355                    Bracketed::new(vec![
6356                        Delimited::new(vec![
6357                            Sequence::new(vec![
6358                                Ref::new("ParameterNameSegment").to_matchable(),
6359                                Ref::new("DatatypeSegment").to_matchable(),
6360                            ])
6361                            .to_matchable(),
6362                        ])
6363                        .to_matchable(),
6364                    ])
6365                    .to_matchable(),
6366                ])
6367                .to_matchable(),
6368            ])
6369            .to_matchable(),
6370        ])
6371        .to_matchable(),
6372    );
6373
6374    postgres.add([(
6375        "AsAliasExpressionSegment".into(),
6376        NodeMatcher::new(SyntaxKind::AliasExpression, |_| {
6377            Sequence::new(vec![
6378                MetaSegment::indent().to_matchable(),
6379                Ref::keyword("AS").to_matchable(),
6380                Ref::new("SingleIdentifierGrammar").to_matchable(),
6381                MetaSegment::dedent().to_matchable(),
6382            ])
6383            .to_matchable()
6384        })
6385        .to_matchable()
6386        .into(),
6387    )]);
6388
6389    postgres.add([(
6390        "OperationClassReferenceSegment".into(),
6391        NodeMatcher::new(SyntaxKind::OperationClassReference, |postgres| {
6392            postgres
6393                .grammar("ObjectReferenceSegment")
6394                .match_grammar(postgres)
6395                .unwrap()
6396        })
6397        .to_matchable()
6398        .into(),
6399    )]);
6400
6401    postgres.add([
6402        (
6403            "ConflictActionSegment".into(),
6404            NodeMatcher::new(SyntaxKind::ConflictAction, |_| {
6405                Sequence::new(vec![
6406                    Ref::keyword("DO").to_matchable(),
6407                    one_of(vec![
6408                        Ref::keyword("NOTHING").to_matchable(),
6409                        Sequence::new(vec![
6410                            Ref::keyword("UPDATE").to_matchable(),
6411                            Ref::keyword("SET").to_matchable(),
6412                            Delimited::new(vec![
6413                                one_of(vec![
6414                                    Sequence::new(vec![
6415                                        Ref::new("ColumnReferenceSegment").to_matchable(),
6416                                        Ref::new("EqualsSegment").to_matchable(),
6417                                        one_of(vec![
6418                                            Ref::new("ExpressionSegment").to_matchable(),
6419                                            Ref::keyword("DEFAULT").to_matchable(),
6420                                        ])
6421                                        .to_matchable(),
6422                                    ])
6423                                    .to_matchable(),
6424                                    Sequence::new(vec![
6425                                        Bracketed::new(vec![
6426                                            Delimited::new(vec![
6427                                                Ref::new("ColumnReferenceSegment").to_matchable(),
6428                                            ])
6429                                            .to_matchable(),
6430                                        ])
6431                                        .to_matchable(),
6432                                        Ref::new("EqualsSegment").to_matchable(),
6433                                        Ref::keyword("ROW").optional().to_matchable(),
6434                                        Bracketed::new(vec![
6435                                            Delimited::new(vec![
6436                                                one_of(vec![
6437                                                    Ref::new("ExpressionSegment").to_matchable(),
6438                                                    Ref::keyword("DEFAULT").to_matchable(),
6439                                                ])
6440                                                .to_matchable(),
6441                                            ])
6442                                            .to_matchable(),
6443                                        ])
6444                                        .to_matchable(),
6445                                    ])
6446                                    .to_matchable(),
6447                                    Sequence::new(vec![
6448                                        Bracketed::new(vec![
6449                                            Delimited::new(vec![
6450                                                Ref::new("ColumnReferenceSegment").to_matchable(),
6451                                            ])
6452                                            .to_matchable(),
6453                                        ])
6454                                        .to_matchable(),
6455                                        Ref::new("EqualsSegment").to_matchable(),
6456                                        Bracketed::new(vec![
6457                                            Ref::new("SelectableGrammar").to_matchable(),
6458                                        ])
6459                                        .to_matchable(),
6460                                    ])
6461                                    .to_matchable(),
6462                                ])
6463                                .to_matchable(),
6464                            ])
6465                            .to_matchable(),
6466                            Sequence::new(vec![
6467                                Ref::keyword("WHERE").to_matchable(),
6468                                Ref::new("ExpressionSegment").to_matchable(),
6469                            ])
6470                            .config(|this| this.optional())
6471                            .to_matchable(),
6472                        ])
6473                        .to_matchable(),
6474                    ])
6475                    .to_matchable(),
6476                ])
6477                .to_matchable()
6478            })
6479            .to_matchable()
6480            .into(),
6481        ),
6482        (
6483            "ConflictTargetSegment".into(),
6484            NodeMatcher::new(SyntaxKind::ConflictTarget, |_| {
6485                one_of(vec![
6486                    Sequence::new(vec![
6487                        Bracketed::new(vec![
6488                            Delimited::new(vec![
6489                                Sequence::new(vec![
6490                                    one_of(vec![
6491                                        Ref::new("ColumnReferenceSegment").to_matchable(),
6492                                        Bracketed::new(vec![
6493                                            Ref::new("ExpressionSegment").to_matchable(),
6494                                        ])
6495                                        .to_matchable(),
6496                                    ])
6497                                    .to_matchable(),
6498                                    Sequence::new(vec![
6499                                        Ref::keyword("COLLATE").to_matchable(),
6500                                        Ref::new("CollationReferenceSegment").to_matchable(),
6501                                    ])
6502                                    .config(|this| this.optional())
6503                                    .to_matchable(),
6504                                    Ref::new("OperationClassReferenceSegment")
6505                                        .optional()
6506                                        .to_matchable(),
6507                                ])
6508                                .to_matchable(),
6509                            ])
6510                            .to_matchable(),
6511                        ])
6512                        .to_matchable(),
6513                        Sequence::new(vec![
6514                            Ref::keyword("WHERE").to_matchable(),
6515                            Ref::new("ExpressionSegment").to_matchable(),
6516                        ])
6517                        .config(|this| this.optional())
6518                        .to_matchable(),
6519                    ])
6520                    .to_matchable(),
6521                    Sequence::new(vec![
6522                        Ref::keyword("ON").to_matchable(),
6523                        Ref::keyword("CONSTRAINT").to_matchable(),
6524                        Ref::new("ParameterNameSegment").to_matchable(),
6525                    ])
6526                    .to_matchable(),
6527                ])
6528                .to_matchable()
6529            })
6530            .to_matchable()
6531            .into(),
6532        ),
6533    ]);
6534
6535    postgres.replace_grammar(
6536        "InsertStatementSegment",
6537        Sequence::new(vec![
6538            Ref::keyword("INSERT").to_matchable(),
6539            Ref::keyword("INTO").to_matchable(),
6540            Ref::new("TableReferenceSegment").to_matchable(),
6541            Ref::new("AsAliasExpressionSegment")
6542                .optional()
6543                .to_matchable(),
6544            Ref::new("BracketedColumnReferenceListGrammar")
6545                .optional()
6546                .to_matchable(),
6547            Sequence::new(vec![
6548                Ref::keyword("OVERRIDING").to_matchable(),
6549                one_of(vec![
6550                    Ref::keyword("SYSTEM").to_matchable(),
6551                    Ref::keyword("USER").to_matchable(),
6552                ])
6553                .to_matchable(),
6554                Ref::keyword("VALUE").to_matchable(),
6555            ])
6556            .config(|this| this.optional())
6557            .to_matchable(),
6558            one_of(vec![
6559                Sequence::new(vec![
6560                    Ref::keyword("DEFAULT").to_matchable(),
6561                    Ref::keyword("VALUES").to_matchable(),
6562                ])
6563                .to_matchable(),
6564                Ref::new("SelectableGrammar").to_matchable(),
6565            ])
6566            .to_matchable(),
6567            Sequence::new(vec![
6568                Ref::keyword("ON").to_matchable(),
6569                Ref::keyword("CONFLICT").to_matchable(),
6570                Ref::new("ConflictTargetSegment").optional().to_matchable(),
6571                Ref::new("ConflictActionSegment").to_matchable(),
6572            ])
6573            .config(|this| this.optional())
6574            .to_matchable(),
6575            Sequence::new(vec![
6576                Ref::keyword("RETURNING").to_matchable(),
6577                MetaSegment::indent().to_matchable(),
6578                one_of(vec![
6579                    Ref::new("StarSegment").to_matchable(),
6580                    Delimited::new(vec![
6581                        Sequence::new(vec![
6582                            Ref::new("ExpressionSegment").to_matchable(),
6583                            Ref::new("AsAliasExpressionSegment")
6584                                .optional()
6585                                .to_matchable(),
6586                        ])
6587                        .to_matchable(),
6588                    ])
6589                    .to_matchable(),
6590                ])
6591                .to_matchable(),
6592                MetaSegment::dedent().to_matchable(),
6593            ])
6594            .config(|this| this.optional())
6595            .to_matchable(),
6596        ])
6597        .to_matchable(),
6598    );
6599
6600    postgres.replace_grammar(
6601        "DropTypeStatementSegment",
6602        Sequence::new(vec![
6603            Ref::keyword("DROP").to_matchable(),
6604            Ref::keyword("TYPE").to_matchable(),
6605            Ref::new("IfExistsGrammar").optional().to_matchable(),
6606            Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(),
6607            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
6608        ])
6609        .to_matchable(),
6610    );
6611
6612    postgres.add([
6613        (
6614            "SetStatementSegment".into(),
6615            NodeMatcher::new(SyntaxKind::SetStatement, |_| {
6616                Sequence::new(vec![
6617                    Ref::keyword("SET").to_matchable(),
6618                    one_of(vec![
6619                        Ref::keyword("SESSION").to_matchable(),
6620                        Ref::keyword("LOCAL").to_matchable(),
6621                    ])
6622                    .config(|this| this.optional())
6623                    .to_matchable(),
6624                    one_of(vec![
6625                        Sequence::new(vec![
6626                            Ref::new("ParameterNameSegment").to_matchable(),
6627                            one_of(vec![
6628                                Ref::keyword("TO").to_matchable(),
6629                                Ref::new("EqualsSegment").to_matchable(),
6630                            ])
6631                            .to_matchable(),
6632                            one_of(vec![
6633                                Ref::keyword("DEFAULT").to_matchable(),
6634                                Delimited::new(vec![
6635                                    Ref::new("LiteralGrammar").to_matchable(),
6636                                    Ref::new("NakedIdentifierSegment").to_matchable(),
6637                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
6638                                    Ref::new("OnKeywordAsIdentifierSegment").to_matchable(),
6639                                ])
6640                                .to_matchable(),
6641                            ])
6642                            .to_matchable(),
6643                        ])
6644                        .to_matchable(),
6645                        Sequence::new(vec![
6646                            Ref::keyword("TIME").to_matchable(),
6647                            Ref::keyword("ZONE").to_matchable(),
6648                            one_of(vec![
6649                                Ref::new("QuotedLiteralSegment").to_matchable(),
6650                                Ref::keyword("LOCAL").to_matchable(),
6651                                Ref::keyword("DEFAULT").to_matchable(),
6652                            ])
6653                            .to_matchable(),
6654                        ])
6655                        .to_matchable(),
6656                        Sequence::new(vec![
6657                            Ref::keyword("SCHEMA").to_matchable(),
6658                            Ref::new("QuotedLiteralSegment").to_matchable(),
6659                        ])
6660                        .to_matchable(),
6661                        Sequence::new(vec![
6662                            Ref::keyword("ROLE").to_matchable(),
6663                            one_of(vec![
6664                                Ref::keyword("NONE").to_matchable(),
6665                                Ref::new("RoleReferenceSegment").to_matchable(),
6666                            ])
6667                            .to_matchable(),
6668                        ])
6669                        .to_matchable(),
6670                    ])
6671                    .to_matchable(),
6672                ])
6673                .to_matchable()
6674            })
6675            .to_matchable()
6676            .into(),
6677        ),
6678        (
6679            "CreatePolicyStatementSegment".into(),
6680            NodeMatcher::new(SyntaxKind::CreatePolicyStatement, |_| {
6681                Sequence::new(vec![
6682                    Ref::keyword("CREATE").to_matchable(),
6683                    Ref::keyword("POLICY").to_matchable(),
6684                    Ref::new("ObjectReferenceSegment").to_matchable(),
6685                    Ref::keyword("ON").to_matchable(),
6686                    Ref::new("TableReferenceSegment").to_matchable(),
6687                    Sequence::new(vec![
6688                        Ref::keyword("AS").to_matchable(),
6689                        one_of(vec![
6690                            Ref::keyword("PERMISSIVE").to_matchable(),
6691                            Ref::keyword("RESTRICTIVE").to_matchable(),
6692                        ])
6693                        .to_matchable(),
6694                    ])
6695                    .config(|this| this.optional())
6696                    .to_matchable(),
6697                    Sequence::new(vec![
6698                        Ref::keyword("FOR").to_matchable(),
6699                        one_of(vec![
6700                            Ref::keyword("ALL").to_matchable(),
6701                            Ref::keyword("SELECT").to_matchable(),
6702                            Ref::keyword("INSERT").to_matchable(),
6703                            Ref::keyword("UPDATE").to_matchable(),
6704                            Ref::keyword("DELETE").to_matchable(),
6705                        ])
6706                        .to_matchable(),
6707                    ])
6708                    .config(|this| this.optional())
6709                    .to_matchable(),
6710                    Sequence::new(vec![
6711                        Ref::keyword("TO").to_matchable(),
6712                        Delimited::new(vec![
6713                            one_of(vec![
6714                                Ref::new("ObjectReferenceSegment").to_matchable(),
6715                                Ref::keyword("PUBLIC").to_matchable(),
6716                                Ref::keyword("CURRENT_ROLE").to_matchable(),
6717                                Ref::keyword("CURRENT_USER").to_matchable(),
6718                                Ref::keyword("SESSION_USER").to_matchable(),
6719                            ])
6720                            .to_matchable(),
6721                        ])
6722                        .to_matchable(),
6723                    ])
6724                    .config(|this| this.optional())
6725                    .to_matchable(),
6726                    Sequence::new(vec![
6727                        Ref::keyword("USING").to_matchable(),
6728                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
6729                            .to_matchable(),
6730                    ])
6731                    .config(|this| this.optional())
6732                    .to_matchable(),
6733                    Sequence::new(vec![
6734                        Ref::keyword("WITH").to_matchable(),
6735                        Ref::keyword("CHECK").to_matchable(),
6736                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
6737                            .to_matchable(),
6738                    ])
6739                    .config(|this| this.optional())
6740                    .to_matchable(),
6741                ])
6742                .to_matchable()
6743            })
6744            .to_matchable()
6745            .into(),
6746        ),
6747        (
6748            "CallStoredProcedureSegment".into(),
6749            NodeMatcher::new(SyntaxKind::CallStatement, |_| {
6750                Sequence::new(vec![
6751                    Ref::keyword("CALL").to_matchable(),
6752                    Ref::new("FunctionSegment").to_matchable(),
6753                ])
6754                .to_matchable()
6755            })
6756            .to_matchable()
6757            .into(),
6758        ),
6759        (
6760            "CreateDomainStatementSegment".into(),
6761            NodeMatcher::new(SyntaxKind::CreateDomainStatement, |_| {
6762                Sequence::new(vec![
6763                    Ref::keyword("CREATE").to_matchable(),
6764                    Ref::keyword("DOMAIN").to_matchable(),
6765                    Ref::new("ObjectReferenceSegment").to_matchable(),
6766                    Sequence::new(vec![Ref::keyword("AS").to_matchable()])
6767                        .config(|this| this.optional())
6768                        .to_matchable(),
6769                    Ref::new("DatatypeSegment").to_matchable(),
6770                    Sequence::new(vec![
6771                        Ref::keyword("COLLATE").to_matchable(),
6772                        Ref::new("CollationReferenceSegment").to_matchable(),
6773                    ])
6774                    .config(|this| this.optional())
6775                    .to_matchable(),
6776                    Sequence::new(vec![
6777                        Ref::keyword("DEFAULT").to_matchable(),
6778                        Ref::new("ExpressionSegment").to_matchable(),
6779                    ])
6780                    .config(|this| this.optional())
6781                    .to_matchable(),
6782                    AnyNumberOf::new(vec![
6783                        Sequence::new(vec![
6784                            Sequence::new(vec![
6785                                Ref::keyword("CONSTRAINT").to_matchable(),
6786                                Ref::new("ObjectReferenceSegment").to_matchable(),
6787                            ])
6788                            .config(|this| this.optional())
6789                            .to_matchable(),
6790                            one_of(vec![
6791                                Sequence::new(vec![
6792                                    Ref::keyword("NOT").optional().to_matchable(),
6793                                    Ref::keyword("NULL").to_matchable(),
6794                                ])
6795                                .to_matchable(),
6796                                Sequence::new(vec![
6797                                    Ref::keyword("CHECK").to_matchable(),
6798                                    Ref::new("ExpressionSegment").to_matchable(),
6799                                ])
6800                                .to_matchable(),
6801                            ])
6802                            .to_matchable(),
6803                        ])
6804                        .to_matchable(),
6805                    ])
6806                    .to_matchable(),
6807                ])
6808                .to_matchable()
6809            })
6810            .to_matchable()
6811            .into(),
6812        ),
6813        (
6814            "AlterDomainStatementSegment".into(),
6815            NodeMatcher::new(SyntaxKind::AlterDomainStatement, |_| {
6816                Sequence::new(vec![
6817                    Ref::keyword("ALTER").to_matchable(),
6818                    Ref::keyword("DOMAIN").to_matchable(),
6819                    Ref::new("ObjectReferenceSegment").to_matchable(),
6820                    one_of(vec![
6821                        Sequence::new(vec![
6822                            Ref::keyword("SET").to_matchable(),
6823                            Ref::keyword("DEFAULT").to_matchable(),
6824                            Ref::new("ExpressionSegment").to_matchable(),
6825                        ])
6826                        .to_matchable(),
6827                        Sequence::new(vec![
6828                            Ref::keyword("DROP").to_matchable(),
6829                            Ref::keyword("DEFAULT").to_matchable(),
6830                        ])
6831                        .to_matchable(),
6832                        Sequence::new(vec![
6833                            one_of(vec![
6834                                Ref::keyword("SET").to_matchable(),
6835                                Ref::keyword("DROP").to_matchable(),
6836                            ])
6837                            .to_matchable(),
6838                            Ref::keyword("NOT").to_matchable(),
6839                            Ref::keyword("NULL").to_matchable(),
6840                        ])
6841                        .to_matchable(),
6842                        Sequence::new(vec![
6843                            Ref::keyword("ADD").to_matchable(),
6844                            Sequence::new(vec![
6845                                Ref::keyword("CONSTRAINT").to_matchable(),
6846                                Ref::new("ObjectReferenceSegment").to_matchable(),
6847                            ])
6848                            .config(|this| this.optional())
6849                            .to_matchable(),
6850                            one_of(vec![
6851                                Sequence::new(vec![
6852                                    Ref::keyword("NOT").optional().to_matchable(),
6853                                    Ref::keyword("NULL").to_matchable(),
6854                                ])
6855                                .to_matchable(),
6856                                Sequence::new(vec![
6857                                    Ref::keyword("CHECK").to_matchable(),
6858                                    Ref::new("ExpressionSegment").to_matchable(),
6859                                ])
6860                                .to_matchable(),
6861                            ])
6862                            .to_matchable(),
6863                            Sequence::new(vec![
6864                                Ref::keyword("NOT").to_matchable(),
6865                                Ref::keyword("VALID").to_matchable(),
6866                            ])
6867                            .config(|this| this.optional())
6868                            .to_matchable(),
6869                        ])
6870                        .to_matchable(),
6871                        Sequence::new(vec![
6872                            Ref::keyword("DROP").to_matchable(),
6873                            Ref::keyword("CONSTRAINT").to_matchable(),
6874                            Ref::new("IfExistsGrammar").optional().to_matchable(),
6875                            Ref::new("ObjectReferenceSegment").to_matchable(),
6876                            one_of(vec![
6877                                Ref::keyword("RESTRICT").to_matchable(),
6878                                Ref::keyword("CASCADE").to_matchable(),
6879                            ])
6880                            .config(|this| this.optional())
6881                            .to_matchable(),
6882                        ])
6883                        .to_matchable(),
6884                        Sequence::new(vec![
6885                            Ref::keyword("RENAME").to_matchable(),
6886                            Ref::keyword("CONSTRAINT").to_matchable(),
6887                            Ref::new("ObjectReferenceSegment").to_matchable(),
6888                            Ref::keyword("TO").to_matchable(),
6889                            Ref::new("ObjectReferenceSegment").to_matchable(),
6890                        ])
6891                        .to_matchable(),
6892                        Sequence::new(vec![
6893                            Ref::keyword("VALIDATE").to_matchable(),
6894                            Ref::keyword("CONSTRAINT").to_matchable(),
6895                            Ref::new("ObjectReferenceSegment").to_matchable(),
6896                        ])
6897                        .to_matchable(),
6898                        Sequence::new(vec![
6899                            Ref::keyword("OWNER").to_matchable(),
6900                            Ref::keyword("TO").to_matchable(),
6901                            one_of(vec![
6902                                Ref::new("ObjectReferenceSegment").to_matchable(),
6903                                Ref::keyword("CURRENT_ROLE").to_matchable(),
6904                                Ref::keyword("CURRENT_USER").to_matchable(),
6905                                Ref::keyword("SESSION_USER").to_matchable(),
6906                            ])
6907                            .to_matchable(),
6908                        ])
6909                        .to_matchable(),
6910                        Sequence::new(vec![
6911                            Ref::keyword("RENAME").to_matchable(),
6912                            Ref::keyword("TO").to_matchable(),
6913                            Ref::new("ObjectReferenceSegment").to_matchable(),
6914                        ])
6915                        .to_matchable(),
6916                        Sequence::new(vec![
6917                            Ref::keyword("SET").to_matchable(),
6918                            Ref::keyword("SCHEMA").to_matchable(),
6919                            Ref::new("ObjectReferenceSegment").to_matchable(),
6920                        ])
6921                        .to_matchable(),
6922                    ])
6923                    .to_matchable(),
6924                ])
6925                .to_matchable()
6926            })
6927            .to_matchable()
6928            .into(),
6929        ),
6930        (
6931            "DropDomainStatementSegment".into(),
6932            NodeMatcher::new(SyntaxKind::DropDomainStatement, |_| {
6933                Sequence::new(vec![
6934                    Ref::keyword("DROP").to_matchable(),
6935                    Ref::keyword("DOMAIN").to_matchable(),
6936                    Ref::new("IfExistsGrammar").optional().to_matchable(),
6937                    Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
6938                        .to_matchable(),
6939                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
6940                ])
6941                .to_matchable()
6942            })
6943            .to_matchable()
6944            .into(),
6945        ),
6946        (
6947            "DropPolicyStatementSegment".into(),
6948            NodeMatcher::new(SyntaxKind::DropPolicyStatement, |_| {
6949                Sequence::new(vec![
6950                    Ref::keyword("DROP").to_matchable(),
6951                    Ref::keyword("POLICY").to_matchable(),
6952                    Ref::new("IfExistsGrammar").optional().to_matchable(),
6953                    Ref::new("ObjectReferenceSegment").to_matchable(),
6954                    Ref::keyword("ON").to_matchable(),
6955                    Ref::new("TableReferenceSegment").to_matchable(),
6956                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
6957                ])
6958                .to_matchable()
6959            })
6960            .to_matchable()
6961            .into(),
6962        ),
6963        (
6964            "LoadStatementSegment".into(),
6965            NodeMatcher::new(SyntaxKind::LoadStatement, |_| {
6966                Sequence::new(vec![
6967                    Ref::keyword("LOAD").to_matchable(),
6968                    Ref::new("QuotedLiteralSegment").to_matchable(),
6969                ])
6970                .to_matchable()
6971            })
6972            .to_matchable()
6973            .into(),
6974        ),
6975        (
6976            "ResetStatementSegment".into(),
6977            NodeMatcher::new(SyntaxKind::ResetStatement, |_| {
6978                Sequence::new(vec![
6979                    Ref::keyword("RESET").to_matchable(),
6980                    one_of(vec![
6981                        Ref::keyword("ALL").to_matchable(),
6982                        Ref::keyword("ROLE").to_matchable(),
6983                        Ref::new("ParameterNameSegment").to_matchable(),
6984                    ])
6985                    .to_matchable(),
6986                ])
6987                .to_matchable()
6988            })
6989            .to_matchable()
6990            .into(),
6991        ),
6992        (
6993            "DiscardStatementSegment".into(),
6994            NodeMatcher::new(SyntaxKind::DiscardStatement, |_| {
6995                Sequence::new(vec![
6996                    Ref::keyword("DISCARD").to_matchable(),
6997                    one_of(vec![
6998                        Ref::keyword("ALL").to_matchable(),
6999                        Ref::keyword("PLANS").to_matchable(),
7000                        Ref::keyword("SEQUENCES").to_matchable(),
7001                        Ref::keyword("TEMPORARY").to_matchable(),
7002                        Ref::keyword("TEMP").to_matchable(),
7003                    ])
7004                    .to_matchable(),
7005                ])
7006                .to_matchable()
7007            })
7008            .to_matchable()
7009            .into(),
7010        ),
7011        (
7012            "ListenStatementSegment".into(),
7013            NodeMatcher::new(SyntaxKind::ListenStatement, |_| {
7014                Sequence::new(vec![
7015                    Ref::keyword("LISTEN").to_matchable(),
7016                    Ref::new("SingleIdentifierGrammar").to_matchable(),
7017                ])
7018                .to_matchable()
7019            })
7020            .to_matchable()
7021            .into(),
7022        ),
7023        (
7024            "NotifyStatementSegment".into(),
7025            NodeMatcher::new(SyntaxKind::NotifyStatement, |_| {
7026                Sequence::new(vec![
7027                    Ref::keyword("NOTIFY").to_matchable(),
7028                    Ref::new("SingleIdentifierGrammar").to_matchable(),
7029                    Sequence::new(vec![
7030                        Ref::new("CommaSegment").to_matchable(),
7031                        Ref::new("QuotedLiteralSegment").to_matchable(),
7032                    ])
7033                    .config(|this| this.optional())
7034                    .to_matchable(),
7035                ])
7036                .to_matchable()
7037            })
7038            .to_matchable()
7039            .into(),
7040        ),
7041        (
7042            "UnlistenStatementSegment".into(),
7043            NodeMatcher::new(SyntaxKind::UnlistenStatement, |_| {
7044                Sequence::new(vec![
7045                    Ref::keyword("UNLISTEN").to_matchable(),
7046                    one_of(vec![
7047                        Ref::new("SingleIdentifierGrammar").to_matchable(),
7048                        Ref::new("StarSegment").to_matchable(),
7049                    ])
7050                    .to_matchable(),
7051                ])
7052                .to_matchable()
7053            })
7054            .to_matchable()
7055            .into(),
7056        ),
7057    ]);
7058
7059    postgres.replace_grammar(
7060        "TruncateStatementSegment",
7061        Sequence::new(vec![
7062            Ref::keyword("TRUNCATE").to_matchable(),
7063            Ref::keyword("TABLE").optional().to_matchable(),
7064            Delimited::new(vec![
7065                one_of(vec![
7066                    Sequence::new(vec![
7067                        Ref::keyword("ONLY").optional().to_matchable(),
7068                        Ref::new("TableReferenceSegment").to_matchable(),
7069                    ])
7070                    .to_matchable(),
7071                    Sequence::new(vec![
7072                        Ref::new("TableReferenceSegment").to_matchable(),
7073                        Ref::new("StarSegment").optional().to_matchable(),
7074                    ])
7075                    .to_matchable(),
7076                ])
7077                .to_matchable(),
7078            ])
7079            .to_matchable(),
7080            Sequence::new(vec![
7081                one_of(vec![
7082                    Ref::keyword("RESTART").to_matchable(),
7083                    Ref::keyword("CONTINUE").to_matchable(),
7084                ])
7085                .to_matchable(),
7086                Ref::keyword("IDENTITY").to_matchable(),
7087            ])
7088            .config(|this| this.optional())
7089            .to_matchable(),
7090            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
7091        ])
7092        .to_matchable(),
7093    );
7094
7095    postgres.add([
7096        (
7097            "CopyStatementSegment".into(),
7098            NodeMatcher::new(SyntaxKind::CopyStatement, |_| {
7099                let _target_subset = one_of(vec![
7100                    Ref::new("QuotedLiteralSegment").to_matchable(),
7101                    Sequence::new(vec![
7102                        Ref::keyword("PROGRAM").to_matchable(),
7103                        Ref::new("QuotedLiteralSegment").to_matchable(),
7104                    ])
7105                    .to_matchable(),
7106                ]);
7107
7108                let _table_definition = Sequence::new(vec![
7109                    Ref::new("TableReferenceSegment").to_matchable(),
7110                    Bracketed::new(vec![
7111                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
7112                            .to_matchable(),
7113                    ])
7114                    .config(|this| this.optional())
7115                    .to_matchable(),
7116                ]);
7117
7118                let _option = Sequence::new(vec![
7119                    Ref::keyword("WITH").optional().to_matchable(),
7120                    Bracketed::new(vec![
7121                        Delimited::new(vec![
7122                            any_set_of(vec![
7123                                Sequence::new(vec![
7124                                    Ref::keyword("FORMAT").to_matchable(),
7125                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
7126                                ])
7127                                .to_matchable(),
7128                                Sequence::new(vec![
7129                                    Ref::keyword("FREEZE").to_matchable(),
7130                                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
7131                                ])
7132                                .to_matchable(),
7133                                Sequence::new(vec![
7134                                    Ref::keyword("DELIMITER").to_matchable(),
7135                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7136                                ])
7137                                .to_matchable(),
7138                                Sequence::new(vec![
7139                                    Ref::keyword("NULL").to_matchable(),
7140                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7141                                ])
7142                                .to_matchable(),
7143                                Sequence::new(vec![
7144                                    Ref::keyword("HEADER").to_matchable(),
7145                                    Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
7146                                ])
7147                                .to_matchable(),
7148                                Sequence::new(vec![
7149                                    Ref::keyword("QUOTE").to_matchable(),
7150                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7151                                ])
7152                                .to_matchable(),
7153                                Sequence::new(vec![
7154                                    Ref::keyword("ESCAPE").to_matchable(),
7155                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7156                                ])
7157                                .to_matchable(),
7158                                Sequence::new(vec![
7159                                    Ref::keyword("FORCE_QUOTE").to_matchable(),
7160                                    one_of(vec![
7161                                        Bracketed::new(vec![
7162                                            Delimited::new(vec![
7163                                                Ref::new("ColumnReferenceSegment").to_matchable(),
7164                                            ])
7165                                            .to_matchable(),
7166                                        ])
7167                                        .to_matchable(),
7168                                        Ref::new("StarSegment").to_matchable(),
7169                                    ])
7170                                    .to_matchable(),
7171                                ])
7172                                .to_matchable(),
7173                                Sequence::new(vec![
7174                                    Ref::keyword("FORCE_NOT_NULL").to_matchable(),
7175                                    Bracketed::new(vec![
7176                                        Delimited::new(vec![
7177                                            Ref::new("ColumnReferenceSegment").to_matchable(),
7178                                        ])
7179                                        .to_matchable(),
7180                                    ])
7181                                    .to_matchable(),
7182                                ])
7183                                .to_matchable(),
7184                                Sequence::new(vec![
7185                                    Ref::keyword("FORCE_NULL").to_matchable(),
7186                                    Bracketed::new(vec![
7187                                        Delimited::new(vec![
7188                                            Ref::new("ColumnReferenceSegment").to_matchable(),
7189                                        ])
7190                                        .to_matchable(),
7191                                    ])
7192                                    .to_matchable(),
7193                                ])
7194                                .to_matchable(),
7195                                Sequence::new(vec![
7196                                    Ref::keyword("ENCODING").to_matchable(),
7197                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7198                                ])
7199                                .to_matchable(),
7200                            ])
7201                            .to_matchable(),
7202                        ])
7203                        .to_matchable(),
7204                    ])
7205                    .to_matchable(),
7206                ])
7207                .config(|this| this.optional());
7208
7209                Sequence::new(vec![
7210                    Ref::keyword("COPY").to_matchable(),
7211                    one_of(vec![
7212                        Sequence::new(vec![
7213                            _table_definition.clone().to_matchable(),
7214                            Ref::keyword("FROM").to_matchable(),
7215                            one_of(vec![
7216                                _target_subset.clone().to_matchable(),
7217                                Ref::keyword("STDIN").to_matchable(),
7218                            ])
7219                            .to_matchable(),
7220                            _option.clone().to_matchable(),
7221                            Sequence::new(vec![
7222                                Ref::keyword("WHERE").to_matchable(),
7223                                Ref::new("ExpressionSegment").to_matchable(),
7224                            ])
7225                            .config(|this| this.optional())
7226                            .to_matchable(),
7227                        ])
7228                        .to_matchable(),
7229                        Sequence::new(vec![
7230                            one_of(vec![
7231                                _table_definition.clone().to_matchable(),
7232                                Bracketed::new(vec![
7233                                    Ref::new("UnorderedSelectStatementSegment").to_matchable(),
7234                                ])
7235                                .to_matchable(),
7236                            ])
7237                            .to_matchable(),
7238                            Ref::keyword("TO").to_matchable(),
7239                            one_of(vec![
7240                                _target_subset.to_matchable(),
7241                                Ref::keyword("STDOUT").to_matchable(),
7242                            ])
7243                            .to_matchable(),
7244                            _option.to_matchable(),
7245                        ])
7246                        .to_matchable(),
7247                    ])
7248                    .to_matchable(),
7249                ])
7250                .to_matchable()
7251            })
7252            .to_matchable()
7253            .into(),
7254        ),
7255        (
7256            "AlterSchemaStatementSegment".into(),
7257            NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_| {
7258                Sequence::new(vec![
7259                    Ref::keyword("ALTER").to_matchable(),
7260                    Ref::keyword("SCHEMA").to_matchable(),
7261                    Ref::new("SchemaReferenceSegment").to_matchable(),
7262                    one_of(vec![
7263                        Sequence::new(vec![
7264                            Ref::keyword("RENAME").to_matchable(),
7265                            Ref::keyword("TO").to_matchable(),
7266                            Ref::new("SchemaReferenceSegment").to_matchable(),
7267                        ])
7268                        .to_matchable(),
7269                        Sequence::new(vec![
7270                            Ref::keyword("OWNER").to_matchable(),
7271                            Ref::keyword("TO").to_matchable(),
7272                            Ref::new("RoleReferenceSegment").to_matchable(),
7273                        ])
7274                        .to_matchable(),
7275                    ])
7276                    .to_matchable(),
7277                ])
7278                .to_matchable()
7279            })
7280            .to_matchable()
7281            .into(),
7282        ),
7283        (
7284            "LockTableStatementSegment".into(),
7285            NodeMatcher::new(SyntaxKind::LockTableStatement, |_| {
7286                Sequence::new(vec![
7287                    Ref::keyword("LOCK").to_matchable(),
7288                    Ref::keyword("TABLE").optional().to_matchable(),
7289                    Ref::keyword("ONLY").optional().to_matchable(),
7290                    one_of(vec![
7291                        Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
7292                            .to_matchable(),
7293                        Ref::new("StarSegment").to_matchable(),
7294                    ])
7295                    .to_matchable(),
7296                    Sequence::new(vec![
7297                        Ref::keyword("IN").to_matchable(),
7298                        one_of(vec![
7299                            Sequence::new(vec![
7300                                Ref::keyword("ACCESS").to_matchable(),
7301                                Ref::keyword("SHARE").to_matchable(),
7302                            ])
7303                            .to_matchable(),
7304                            Sequence::new(vec![
7305                                Ref::keyword("ROW").to_matchable(),
7306                                Ref::keyword("SHARE").to_matchable(),
7307                            ])
7308                            .to_matchable(),
7309                            Sequence::new(vec![
7310                                Ref::keyword("ROW").to_matchable(),
7311                                Ref::keyword("EXCLUSIVE").to_matchable(),
7312                            ])
7313                            .to_matchable(),
7314                            Sequence::new(vec![
7315                                Ref::keyword("SHARE").to_matchable(),
7316                                Ref::keyword("UPDATE").to_matchable(),
7317                                Ref::keyword("EXCLUSIVE").to_matchable(),
7318                            ])
7319                            .to_matchable(),
7320                            Ref::keyword("SHARE").to_matchable(),
7321                            Sequence::new(vec![
7322                                Ref::keyword("SHARE").to_matchable(),
7323                                Ref::keyword("ROW").to_matchable(),
7324                                Ref::keyword("EXCLUSIVE").to_matchable(),
7325                            ])
7326                            .to_matchable(),
7327                            Ref::keyword("EXCLUSIVE").to_matchable(),
7328                            Sequence::new(vec![
7329                                Ref::keyword("ACCESS").to_matchable(),
7330                                Ref::keyword("EXCLUSIVE").to_matchable(),
7331                            ])
7332                            .to_matchable(),
7333                        ])
7334                        .to_matchable(),
7335                        Ref::keyword("MODE").to_matchable(),
7336                    ])
7337                    .config(|this| this.optional())
7338                    .to_matchable(),
7339                    Ref::keyword("NOWAIT").optional().to_matchable(),
7340                ])
7341                .to_matchable()
7342            })
7343            .to_matchable()
7344            .into(),
7345        ),
7346        (
7347            "ClusterStatementSegment".into(),
7348            NodeMatcher::new(SyntaxKind::ClusterStatement, |_| {
7349                Sequence::new(vec![
7350                    Ref::keyword("CLUSTER").to_matchable(),
7351                    Ref::keyword("VERBOSE").optional().to_matchable(),
7352                    one_of(vec![
7353                        Sequence::new(vec![
7354                            Ref::new("TableReferenceSegment").to_matchable(),
7355                            Sequence::new(vec![
7356                                Ref::keyword("USING").to_matchable(),
7357                                Ref::new("IndexReferenceSegment").to_matchable(),
7358                            ])
7359                            .config(|this| this.optional())
7360                            .to_matchable(),
7361                        ])
7362                        .to_matchable(),
7363                        Sequence::new(vec![
7364                            Ref::new("IndexReferenceSegment").to_matchable(),
7365                            Ref::keyword("ON").to_matchable(),
7366                            Ref::new("TableReferenceSegment").to_matchable(),
7367                        ])
7368                        .to_matchable(),
7369                    ])
7370                    .config(|this| this.optional())
7371                    .to_matchable(),
7372                ])
7373                .to_matchable()
7374            })
7375            .to_matchable()
7376            .into(),
7377        ),
7378        (
7379            "LanguageClauseSegment".into(),
7380            NodeMatcher::new(SyntaxKind::LanguageClause, |_| {
7381                Sequence::new(vec![
7382                    Ref::keyword("LANGUAGE").to_matchable(),
7383                    one_of(vec![
7384                        Ref::new("NakedIdentifierSegment").to_matchable(),
7385                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
7386                    ])
7387                    .to_matchable(),
7388                ])
7389                .to_matchable()
7390            })
7391            .to_matchable()
7392            .into(),
7393        ),
7394        (
7395            "DoStatementSegment".into(),
7396            NodeMatcher::new(SyntaxKind::DoStatement, |_| {
7397                Sequence::new(vec![
7398                    Ref::keyword("DO").to_matchable(),
7399                    one_of(vec![
7400                        Sequence::new(vec![
7401                            Ref::new("LanguageClauseSegment").optional().to_matchable(),
7402                            Ref::new("QuotedLiteralSegment").to_matchable(),
7403                        ])
7404                        .to_matchable(),
7405                        Sequence::new(vec![
7406                            Ref::new("QuotedLiteralSegment").to_matchable(),
7407                            Ref::new("LanguageClauseSegment").optional().to_matchable(),
7408                        ])
7409                        .to_matchable(),
7410                    ])
7411                    .to_matchable(),
7412                ])
7413                .to_matchable()
7414            })
7415            .to_matchable()
7416            .into(),
7417        ),
7418    ]);
7419
7420    postgres.replace_grammar(
7421        "CTEDefinitionSegment",
7422        Sequence::new(vec![
7423            Ref::new("SingleIdentifierGrammar").to_matchable(),
7424            Ref::new("CTEColumnList").optional().to_matchable(),
7425            Ref::keyword("AS").to_matchable(),
7426            Sequence::new(vec![
7427                Ref::keyword("NOT").optional().to_matchable(),
7428                Ref::keyword("MATERIALIZED").to_matchable(),
7429            ])
7430            .config(|this| this.optional())
7431            .to_matchable(),
7432            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
7433                .config(|this| this.parse_mode = ParseMode::Greedy)
7434                .to_matchable(),
7435            one_of(vec![
7436                Sequence::new(vec![
7437                    Ref::keyword("SEARCH").to_matchable(),
7438                    one_of(vec![
7439                        Ref::keyword("BREADTH").to_matchable(),
7440                        Ref::keyword("DEPTH").to_matchable(),
7441                    ])
7442                    .to_matchable(),
7443                    Ref::keyword("FIRST").to_matchable(),
7444                    Ref::keyword("BY").to_matchable(),
7445                    Ref::new("ColumnReferenceSegment").to_matchable(),
7446                    Ref::keyword("SET").to_matchable(),
7447                    Ref::new("ColumnReferenceSegment").to_matchable(),
7448                ])
7449                .to_matchable(),
7450                Sequence::new(vec![
7451                    Ref::keyword("CYCLE").to_matchable(),
7452                    Ref::new("ColumnReferenceSegment").to_matchable(),
7453                    Ref::keyword("SET").to_matchable(),
7454                    Ref::new("ColumnReferenceSegment").to_matchable(),
7455                    Ref::keyword("USING").to_matchable(),
7456                    Ref::new("ColumnReferenceSegment").to_matchable(),
7457                ])
7458                .to_matchable(),
7459            ])
7460            .config(|this| this.optional())
7461            .to_matchable(),
7462        ])
7463        .to_matchable(),
7464    );
7465
7466    postgres.replace_grammar(
7467        "ValuesClauseSegment",
7468        Sequence::new(vec![
7469            Ref::keyword("VALUES").to_matchable(),
7470            Delimited::new(vec![
7471                Bracketed::new(vec![
7472                    Delimited::new(vec![
7473                        Ref::new("ExpressionSegment").to_matchable(),
7474                        Ref::keyword("DEFAULT").to_matchable(),
7475                    ])
7476                    .config(|this| this.parse_mode = ParseMode::Greedy)
7477                    .to_matchable(),
7478                ])
7479                .to_matchable(),
7480            ])
7481            .to_matchable(),
7482            Ref::new("AliasExpressionSegment").optional().to_matchable(),
7483            Ref::new("OrderByClauseSegment").optional().to_matchable(),
7484            Ref::new("LimitClauseSegment").optional().to_matchable(),
7485        ])
7486        .to_matchable(),
7487    );
7488
7489    postgres.replace_grammar(
7490        "DeleteStatementSegment",
7491        Sequence::new(vec![
7492            Ref::keyword("DELETE").to_matchable(),
7493            Ref::keyword("FROM").to_matchable(),
7494            Ref::keyword("ONLY").optional().to_matchable(),
7495            Ref::new("TableReferenceSegment").to_matchable(),
7496            Ref::new("StarSegment").optional().to_matchable(),
7497            Ref::new("AliasExpressionSegment").optional().to_matchable(),
7498            Sequence::new(vec![
7499                Ref::keyword("USING").to_matchable(),
7500                MetaSegment::indent().to_matchable(),
7501                Delimited::new(vec![
7502                    Sequence::new(vec![
7503                        Ref::new("TableExpressionSegment").to_matchable(),
7504                        Ref::new("AliasExpressionSegment").optional().to_matchable(),
7505                    ])
7506                    .to_matchable(),
7507                ])
7508                .to_matchable(),
7509                MetaSegment::dedent().to_matchable(),
7510            ])
7511            .config(|this| this.optional())
7512            .to_matchable(),
7513            one_of(vec![
7514                Sequence::new(vec![
7515                    Ref::keyword("WHERE").to_matchable(),
7516                    Ref::keyword("CURRENT").to_matchable(),
7517                    Ref::keyword("OF").to_matchable(),
7518                    Ref::new("ObjectReferenceSegment").to_matchable(),
7519                ])
7520                .to_matchable(),
7521                Ref::new("WhereClauseSegment").to_matchable(),
7522            ])
7523            .config(|this| this.optional())
7524            .to_matchable(),
7525            Sequence::new(vec![
7526                Ref::keyword("RETURNING").to_matchable(),
7527                MetaSegment::indent().to_matchable(),
7528                one_of(vec![
7529                    Ref::new("StarSegment").to_matchable(),
7530                    Delimited::new(vec![
7531                        Sequence::new(vec![
7532                            Ref::new("ExpressionSegment").to_matchable(),
7533                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
7534                        ])
7535                        .to_matchable(),
7536                    ])
7537                    .to_matchable(),
7538                ])
7539                .to_matchable(),
7540                MetaSegment::dedent().to_matchable(),
7541            ])
7542            .config(|this| this.optional())
7543            .to_matchable(),
7544        ])
7545        .to_matchable(),
7546    );
7547
7548    postgres.add([
7549        (
7550            "SetClauseSegment".into(),
7551            NodeMatcher::new(SyntaxKind::SetClause, |_| {
7552                Sequence::new(vec![
7553                    one_of(vec![
7554                        Sequence::new(vec![
7555                            Ref::new("ColumnReferenceSegment").to_matchable(),
7556                            Ref::new("ArrayAccessorSegment").optional().to_matchable(),
7557                            Ref::new("EqualsSegment").to_matchable(),
7558                            one_of(vec![
7559                                Ref::new("LiteralGrammar").to_matchable(),
7560                                Ref::new("BareFunctionSegment").to_matchable(),
7561                                Ref::new("FunctionSegment").to_matchable(),
7562                                Ref::new("ColumnReferenceSegment").to_matchable(),
7563                                Ref::new("ExpressionSegment").to_matchable(),
7564                                Ref::keyword("DEFAULT").to_matchable(),
7565                            ])
7566                            .to_matchable(),
7567                            AnyNumberOf::new(vec![Ref::new("ShorthandCastSegment").to_matchable()])
7568                                .to_matchable(),
7569                        ])
7570                        .to_matchable(),
7571                        Sequence::new(vec![
7572                            Bracketed::new(vec![
7573                                Delimited::new(vec![
7574                                    Ref::new("ColumnReferenceSegment").to_matchable(),
7575                                ])
7576                                .to_matchable(),
7577                            ])
7578                            .to_matchable(),
7579                            Ref::new("EqualsSegment").to_matchable(),
7580                            Bracketed::new(vec![
7581                                one_of(vec![
7582                                    Ref::new("SelectableGrammar").to_matchable(),
7583                                    Delimited::new(vec![
7584                                        Sequence::new(vec![
7585                                            one_of(vec![
7586                                                Ref::new("LiteralGrammar").to_matchable(),
7587                                                Ref::new("BareFunctionSegment").to_matchable(),
7588                                                Ref::new("FunctionSegment").to_matchable(),
7589                                                Ref::new("ColumnReferenceSegment").to_matchable(),
7590                                                Ref::new("ExpressionSegment").to_matchable(),
7591                                                Ref::keyword("DEFAULT").to_matchable(),
7592                                            ])
7593                                            .to_matchable(),
7594                                            AnyNumberOf::new(vec![
7595                                                Ref::new("ShorthandCastSegment").to_matchable(),
7596                                            ])
7597                                            .to_matchable(),
7598                                        ])
7599                                        .to_matchable(),
7600                                    ])
7601                                    .to_matchable(),
7602                                ])
7603                                .to_matchable(),
7604                            ])
7605                            .to_matchable(),
7606                        ])
7607                        .to_matchable(),
7608                    ])
7609                    .to_matchable(),
7610                ])
7611                .to_matchable()
7612            })
7613            .to_matchable()
7614            .into(),
7615        ),
7616        (
7617            "UpdateStatementSegment".into(),
7618            NodeMatcher::new(SyntaxKind::UpdateStatement, |_| {
7619                Sequence::new(vec![
7620                    Ref::keyword("UPDATE").to_matchable(),
7621                    Ref::keyword("ONLY").optional().to_matchable(),
7622                    Ref::new("TableReferenceSegment").to_matchable(),
7623                    Ref::new("AliasExpressionSegment")
7624                        .exclude(Ref::keyword("SET"))
7625                        .optional()
7626                        .to_matchable(),
7627                    Ref::new("SetClauseListSegment").to_matchable(),
7628                    Ref::new("FromClauseSegment").optional().to_matchable(),
7629                    one_of(vec![
7630                        Sequence::new(vec![
7631                            Ref::keyword("WHERE").to_matchable(),
7632                            Ref::keyword("CURRENT").to_matchable(),
7633                            Ref::keyword("OF").to_matchable(),
7634                            Ref::new("ObjectReferenceSegment").to_matchable(),
7635                        ])
7636                        .to_matchable(),
7637                        Ref::new("WhereClauseSegment").to_matchable(),
7638                    ])
7639                    .config(|this| this.optional())
7640                    .to_matchable(),
7641                    Sequence::new(vec![
7642                        Ref::keyword("RETURNING").to_matchable(),
7643                        MetaSegment::indent().to_matchable(),
7644                        one_of(vec![
7645                            Ref::new("StarSegment").to_matchable(),
7646                            Delimited::new(vec![
7647                                Sequence::new(vec![
7648                                    Ref::new("ExpressionSegment").to_matchable(),
7649                                    Ref::new("AliasExpressionSegment").optional().to_matchable(),
7650                                ])
7651                                .to_matchable(),
7652                            ])
7653                            .to_matchable(),
7654                        ])
7655                        .to_matchable(),
7656                        MetaSegment::dedent().to_matchable(),
7657                    ])
7658                    .config(|this| this.optional())
7659                    .to_matchable(),
7660                ])
7661                .to_matchable()
7662            })
7663            .to_matchable()
7664            .into(),
7665        ),
7666        (
7667            "CreateTypeStatementSegment".into(),
7668            NodeMatcher::new(SyntaxKind::CreateTypeStatement, |_| {
7669                Sequence::new(vec![
7670                    Ref::keyword("CREATE").to_matchable(),
7671                    Ref::keyword("TYPE").to_matchable(),
7672                    Ref::new("ObjectReferenceSegment").to_matchable(),
7673                    Sequence::new(vec![
7674                        Ref::keyword("AS").to_matchable(),
7675                        one_of(vec![
7676                            Ref::keyword("ENUM").to_matchable(),
7677                            Ref::keyword("RANGE").to_matchable(),
7678                        ])
7679                        .config(|this| this.optional())
7680                        .to_matchable(),
7681                    ])
7682                    .config(|this| this.optional())
7683                    .to_matchable(),
7684                    Bracketed::new(vec![
7685                        Delimited::new(vec![
7686                            one_of(vec![
7687                                Sequence::new(vec![
7688                                    Ref::new("ColumnReferenceSegment").to_matchable(),
7689                                    Ref::new("DatatypeSegment").to_matchable(),
7690                                    Sequence::new(vec![
7691                                        Ref::keyword("COLLATE").to_matchable(),
7692                                        Ref::new("CollationReferenceSegment").to_matchable(),
7693                                    ])
7694                                    .config(|this| this.optional())
7695                                    .to_matchable(),
7696                                ])
7697                                .to_matchable(),
7698                                Anything::new().to_matchable(),
7699                            ])
7700                            .to_matchable(),
7701                        ])
7702                        .config(|this| this.optional())
7703                        .to_matchable(),
7704                    ])
7705                    .config(|this| this.optional())
7706                    .to_matchable(),
7707                ])
7708                .to_matchable()
7709            })
7710            .to_matchable()
7711            .into(),
7712        ),
7713        (
7714            "AlterTypeStatementSegment".into(),
7715            NodeMatcher::new(SyntaxKind::AlterTypeStatement, |_| {
7716                Sequence::new(vec![
7717                    Ref::keyword("ALTER").to_matchable(),
7718                    Ref::keyword("TYPE").to_matchable(),
7719                    Ref::new("ObjectReferenceSegment").to_matchable(),
7720                    one_of(vec![
7721                        Sequence::new(vec![
7722                            Ref::keyword("OWNER").to_matchable(),
7723                            Ref::keyword("TO").to_matchable(),
7724                            one_of(vec![
7725                                Ref::keyword("CURRENT_USER").to_matchable(),
7726                                Ref::keyword("SESSION_USER").to_matchable(),
7727                                Ref::keyword("CURRENT_ROLE").to_matchable(),
7728                                Ref::new("ObjectReferenceSegment").to_matchable(),
7729                            ])
7730                            .to_matchable(),
7731                        ])
7732                        .to_matchable(),
7733                        Sequence::new(vec![
7734                            Ref::keyword("RENAME").to_matchable(),
7735                            Ref::keyword("VALUE").to_matchable(),
7736                            Ref::new("QuotedLiteralSegment").to_matchable(),
7737                            Ref::keyword("TO").to_matchable(),
7738                            Ref::new("QuotedLiteralSegment").to_matchable(),
7739                        ])
7740                        .to_matchable(),
7741                        Sequence::new(vec![
7742                            Ref::keyword("RENAME").to_matchable(),
7743                            Ref::keyword("TO").to_matchable(),
7744                            Ref::new("ObjectReferenceSegment").to_matchable(),
7745                        ])
7746                        .to_matchable(),
7747                        Sequence::new(vec![
7748                            Ref::keyword("SET").to_matchable(),
7749                            Ref::keyword("SCHEMA").to_matchable(),
7750                            Ref::new("SchemaReferenceSegment").to_matchable(),
7751                        ])
7752                        .to_matchable(),
7753                        Delimited::new(vec![
7754                            Sequence::new(vec![
7755                                Ref::keyword("ADD").to_matchable(),
7756                                Ref::keyword("ATTRIBUTE").to_matchable(),
7757                                Ref::new("ColumnReferenceSegment").to_matchable(),
7758                                Ref::new("DatatypeSegment").to_matchable(),
7759                                Sequence::new(vec![
7760                                    Ref::keyword("COLLATE").to_matchable(),
7761                                    Ref::new("CollationReferenceSegment").to_matchable(),
7762                                ])
7763                                .config(|this| this.optional())
7764                                .to_matchable(),
7765                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
7766                            ])
7767                            .to_matchable(),
7768                            Sequence::new(vec![
7769                                Ref::keyword("ALTER").to_matchable(),
7770                                Ref::keyword("ATTRIBUTE").to_matchable(),
7771                                Ref::new("ColumnReferenceSegment").to_matchable(),
7772                                Sequence::new(vec![
7773                                    Ref::keyword("SET").to_matchable(),
7774                                    Ref::keyword("DATA").to_matchable(),
7775                                ])
7776                                .config(|this| this.optional())
7777                                .to_matchable(),
7778                                Ref::keyword("TYPE").to_matchable(),
7779                                Ref::new("DatatypeSegment").to_matchable(),
7780                                Sequence::new(vec![
7781                                    Ref::keyword("COLLATE").to_matchable(),
7782                                    Ref::new("CollationReferenceSegment").to_matchable(),
7783                                ])
7784                                .config(|this| this.optional())
7785                                .to_matchable(),
7786                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
7787                            ])
7788                            .to_matchable(),
7789                            Sequence::new(vec![
7790                                Ref::keyword("DROP").to_matchable(),
7791                                Ref::keyword("ATTRIBUTE").to_matchable(),
7792                                Ref::new("IfExistsGrammar").optional().to_matchable(),
7793                                Ref::new("ColumnReferenceSegment").to_matchable(),
7794                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
7795                            ])
7796                            .to_matchable(),
7797                            Sequence::new(vec![
7798                                Ref::keyword("RENAME").to_matchable(),
7799                                Ref::keyword("ATTRIBUTE").to_matchable(),
7800                                Ref::new("ColumnReferenceSegment").to_matchable(),
7801                                Ref::keyword("TO").to_matchable(),
7802                                Ref::new("ColumnReferenceSegment").to_matchable(),
7803                                Ref::new("CascadeRestrictGrammar").optional().to_matchable(),
7804                            ])
7805                            .to_matchable(),
7806                        ])
7807                        .to_matchable(),
7808                        Sequence::new(vec![
7809                            Ref::keyword("ADD").to_matchable(),
7810                            Ref::keyword("VALUE").to_matchable(),
7811                            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
7812                            Ref::new("QuotedLiteralSegment").to_matchable(),
7813                            Sequence::new(vec![
7814                                one_of(vec![
7815                                    Ref::keyword("BEFORE").to_matchable(),
7816                                    Ref::keyword("AFTER").to_matchable(),
7817                                ])
7818                                .to_matchable(),
7819                                Ref::new("QuotedLiteralSegment").to_matchable(),
7820                            ])
7821                            .config(|this| this.optional())
7822                            .to_matchable(),
7823                        ])
7824                        .to_matchable(),
7825                    ])
7826                    .to_matchable(),
7827                ])
7828                .to_matchable()
7829            })
7830            .to_matchable()
7831            .into(),
7832        ),
7833        (
7834            "CreateCollationStatementSegment".into(),
7835            NodeMatcher::new(SyntaxKind::CreateCollationStatement, |_| {
7836                Sequence::new(vec![
7837                    Ref::keyword("CREATE").to_matchable(),
7838                    Ref::keyword("COLLATION").to_matchable(),
7839                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
7840                    Ref::new("ObjectReferenceSegment").to_matchable(),
7841                    one_of(vec![
7842                        Bracketed::new(vec![
7843                            Delimited::new(vec![
7844                                Sequence::new(vec![
7845                                    Ref::keyword("LOCALE").to_matchable(),
7846                                    Ref::new("EqualsSegment").to_matchable(),
7847                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7848                                ])
7849                                .to_matchable(),
7850                                Sequence::new(vec![
7851                                    Ref::keyword("LC_COLLATE").to_matchable(),
7852                                    Ref::new("EqualsSegment").to_matchable(),
7853                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7854                                ])
7855                                .to_matchable(),
7856                                Sequence::new(vec![
7857                                    Ref::keyword("LC_CTYPE").to_matchable(),
7858                                    Ref::new("EqualsSegment").to_matchable(),
7859                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7860                                ])
7861                                .to_matchable(),
7862                                Sequence::new(vec![
7863                                    Ref::keyword("PROVIDER").to_matchable(),
7864                                    Ref::new("EqualsSegment").to_matchable(),
7865                                    one_of(vec![
7866                                        Ref::keyword("ICU").to_matchable(),
7867                                        Ref::keyword("LIBC").to_matchable(),
7868                                    ])
7869                                    .to_matchable(),
7870                                ])
7871                                .to_matchable(),
7872                                Sequence::new(vec![
7873                                    Ref::keyword("DETERMINISTIC").to_matchable(),
7874                                    Ref::new("EqualsSegment").to_matchable(),
7875                                    Ref::new("BooleanLiteralGrammar").to_matchable(),
7876                                ])
7877                                .to_matchable(),
7878                                Sequence::new(vec![
7879                                    Ref::keyword("VERSION").to_matchable(),
7880                                    Ref::new("EqualsSegment").to_matchable(),
7881                                    Ref::new("QuotedLiteralSegment").to_matchable(),
7882                                ])
7883                                .to_matchable(),
7884                            ])
7885                            .to_matchable(),
7886                        ])
7887                        .to_matchable(),
7888                        Sequence::new(vec![
7889                            Ref::keyword("FROM").to_matchable(),
7890                            Ref::new("ObjectReferenceSegment").to_matchable(),
7891                        ])
7892                        .to_matchable(),
7893                    ])
7894                    .to_matchable(),
7895                ])
7896                .to_matchable()
7897            })
7898            .to_matchable()
7899            .into(),
7900        ),
7901    ]);
7902
7903    postgres.replace_grammar(
7904        "ColumnReferenceSegment",
7905        Sequence::new(vec![
7906            Ref::new("SingleIdentifierGrammar").to_matchable(),
7907            Sequence::new(vec![
7908                one_of(vec![
7909                    Ref::new("DotSegment").to_matchable(),
7910                    Sequence::new(vec![
7911                        Ref::new("DotSegment").to_matchable(),
7912                        Ref::new("DotSegment").to_matchable(),
7913                    ])
7914                    .to_matchable(),
7915                ])
7916                .to_matchable(),
7917                Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()])
7918                    .config(|this| {
7919                        this.delimiter(one_of(vec![
7920                            Ref::new("DotSegment").to_matchable(),
7921                            Sequence::new(vec![
7922                                Ref::new("DotSegment").to_matchable(),
7923                                Ref::new("DotSegment").to_matchable(),
7924                            ])
7925                            .to_matchable(),
7926                        ]));
7927                        this.terminators = vec![
7928                            Ref::keyword("ON").to_matchable(),
7929                            Ref::keyword("AS").to_matchable(),
7930                            Ref::keyword("USING").to_matchable(),
7931                            Ref::new("CommaSegment").to_matchable(),
7932                            Ref::new("CastOperatorSegment").to_matchable(),
7933                            Ref::new("StartSquareBracketSegment").to_matchable(),
7934                            Ref::new("StartBracketSegment").to_matchable(),
7935                            Ref::new("BinaryOperatorGrammar").to_matchable(),
7936                            Ref::new("ColonSegment").to_matchable(),
7937                            Ref::new("DelimiterGrammar").to_matchable(),
7938                            Ref::new("JoinLikeClauseGrammar").to_matchable(),
7939                            Bracketed::new(vec![]).to_matchable(),
7940                        ];
7941                        this.allow_gaps = false;
7942                    })
7943                    .to_matchable(),
7944            ])
7945            .config(|this| {
7946                this.optional();
7947                this.allow_gaps = false
7948            })
7949            .to_matchable(),
7950        ])
7951        .config(|this| this.allow_gaps = false)
7952        .to_matchable(),
7953    );
7954
7955    postgres.add([(
7956        "NamedArgumentSegment".into(),
7957        NodeMatcher::new(SyntaxKind::NamedArgument, |_| {
7958            Sequence::new(vec![
7959                Ref::new("NakedIdentifierSegment").to_matchable(),
7960                Ref::new("RightArrowSegment").to_matchable(),
7961                Ref::new("ExpressionSegment").to_matchable(),
7962            ])
7963            .to_matchable()
7964        })
7965        .to_matchable()
7966        .into(),
7967    )]);
7968
7969    postgres.replace_grammar(
7970        "TableExpressionSegment",
7971        one_of(vec![
7972            Ref::new("ValuesClauseSegment").to_matchable(),
7973            Ref::new("BareFunctionSegment").to_matchable(),
7974            Sequence::new(vec![
7975                Ref::new("FunctionSegment").to_matchable(),
7976                Sequence::new(vec![
7977                    Ref::keyword("WITH").to_matchable(),
7978                    Ref::keyword("ORDINALITY").to_matchable(),
7979                ])
7980                .config(|this| this.optional())
7981                .to_matchable(),
7982            ])
7983            .to_matchable(),
7984            Ref::new("TableReferenceSegment").to_matchable(),
7985            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(),
7986            Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]).to_matchable(),
7987        ])
7988        .to_matchable(),
7989    );
7990
7991    postgres.add([(
7992        "ServerReferenceSegment".into(),
7993        NodeMatcher::new(SyntaxKind::ServerReference, |postgres| {
7994            postgres
7995                .grammar("ObjectReferenceSegment")
7996                .match_grammar(postgres)
7997                .unwrap()
7998        })
7999        .to_matchable()
8000        .into(),
8001    )]);
8002
8003    postgres.add([
8004        (
8005            "CreateServerStatementSegment".into(),
8006            NodeMatcher::new(SyntaxKind::CreateServerStatement, |_| {
8007                Sequence::new(vec![
8008                    Ref::keyword("CREATE").to_matchable(),
8009                    Ref::keyword("SERVER").to_matchable(),
8010                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
8011                    Ref::new("ServerReferenceSegment").to_matchable(),
8012                    Sequence::new(vec![
8013                        Ref::keyword("TYPE").to_matchable(),
8014                        Ref::new("QuotedLiteralSegment").to_matchable(),
8015                    ])
8016                    .config(|this| this.optional())
8017                    .to_matchable(),
8018                    Sequence::new(vec![
8019                        Ref::keyword("VERSION").to_matchable(),
8020                        Ref::new("VersionIdentifierSegment").to_matchable(),
8021                    ])
8022                    .config(|this| this.optional())
8023                    .to_matchable(),
8024                    Ref::new("ForeignDataWrapperGrammar").to_matchable(),
8025                    Ref::new("ObjectReferenceSegment").to_matchable(),
8026                    Ref::new("OptionsGrammar").optional().to_matchable(),
8027                ])
8028                .to_matchable()
8029            })
8030            .to_matchable()
8031            .into(),
8032        ),
8033        (
8034            "CreateUserMappingStatementSegment".into(),
8035            NodeMatcher::new(SyntaxKind::CreateUserMappingStatement, |_| {
8036                Sequence::new(vec![
8037                    Ref::new("CreateUserMappingGrammar").to_matchable(),
8038                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
8039                    Ref::keyword("FOR").to_matchable(),
8040                    one_of(vec![
8041                        Ref::new("SingleIdentifierGrammar").to_matchable(),
8042                        Ref::new("SessionInformationUserFunctionsGrammar").to_matchable(),
8043                        Ref::keyword("PUBLIC").to_matchable(),
8044                    ])
8045                    .to_matchable(),
8046                    Ref::keyword("SERVER").to_matchable(),
8047                    Ref::new("ServerReferenceSegment").to_matchable(),
8048                    Ref::new("OptionsGrammar").optional().to_matchable(),
8049                ])
8050                .to_matchable()
8051            })
8052            .to_matchable()
8053            .into(),
8054        ),
8055        (
8056            "ImportForeignSchemaStatementSegment".into(),
8057            NodeMatcher::new(SyntaxKind::ImportForeignSchemaStatement, |_| {
8058                Sequence::new(vec![
8059                    Ref::new("ImportForeignSchemaGrammar").to_matchable(),
8060                    Ref::new("SchemaReferenceSegment").to_matchable(),
8061                    Sequence::new(vec![
8062                        one_of(vec![
8063                            Sequence::new(vec![
8064                                Ref::keyword("LIMIT").to_matchable(),
8065                                Ref::keyword("TO").to_matchable(),
8066                            ])
8067                            .to_matchable(),
8068                            Ref::keyword("EXCEPT").to_matchable(),
8069                        ])
8070                        .to_matchable(),
8071                        Bracketed::new(vec![
8072                            Delimited::new(vec![
8073                                Ref::new("NakedIdentifierFullSegment").to_matchable(),
8074                            ])
8075                            .to_matchable(),
8076                        ])
8077                        .to_matchable(),
8078                    ])
8079                    .config(|this| this.optional())
8080                    .to_matchable(),
8081                    Ref::keyword("FROM").to_matchable(),
8082                    Ref::keyword("SERVER").to_matchable(),
8083                    Ref::new("ServerReferenceSegment").to_matchable(),
8084                    Ref::keyword("INTO").to_matchable(),
8085                    Ref::new("SchemaReferenceSegment").to_matchable(),
8086                    Ref::new("OptionsGrammar").optional().to_matchable(),
8087                ])
8088                .to_matchable()
8089            })
8090            .to_matchable()
8091            .into(),
8092        ),
8093        (
8094            // Statics Reference
8095            "StatisticsReferenceSegment".into(),
8096            Ref::new("ObjectReferenceSegment").to_matchable().into(),
8097        ),
8098        (
8099            // Create Statistics Segment.
8100            // As specified in https://www.postgresql.org/docs/16/sql-createstatistics.html
8101            "CreateStatisticsStatementSegment".into(),
8102            Sequence::new(vec![
8103                Ref::keyword("CREATE").to_matchable(),
8104                Ref::keyword("STATISTICS").to_matchable(),
8105                Sequence::new(vec![
8106                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
8107                    Ref::new("StatisticsReferenceSegment").to_matchable(),
8108                ])
8109                .config(|this| this.optional())
8110                .to_matchable(),
8111                Bracketed::new(vec![
8112                    Delimited::new(vec![
8113                        Ref::keyword("DEPENDENCIES").to_matchable(),
8114                        Ref::keyword("MCV").to_matchable(),
8115                        Ref::keyword("NDISTINCT").to_matchable(),
8116                    ])
8117                    .to_matchable(),
8118                ])
8119                .config(|this| this.optional())
8120                .to_matchable(),
8121                Ref::keyword("ON").to_matchable(),
8122                Delimited::new(vec![
8123                    Ref::new("ColumnReferenceSegment").to_matchable(),
8124                    Ref::new("ExpressionSegment").to_matchable(),
8125                ])
8126                .to_matchable(),
8127                Ref::keyword("FROM").to_matchable(),
8128                Ref::new("TableReferenceSegment").to_matchable(),
8129            ])
8130            .to_matchable()
8131            .into(),
8132        ),
8133        (
8134            // Alter Statistics Segment.
8135            // As specified in https://www.postgresql.org/docs/16/sql-alterstatistics.html
8136            "AlterStatisticsStatementSegment".into(),
8137            Sequence::new(vec![
8138                Ref::keyword("ALTER").to_matchable(),
8139                Ref::keyword("STATISTICS").to_matchable(),
8140                Ref::new("StatisticsReferenceSegment").to_matchable(),
8141                one_of(vec![
8142                    Sequence::new(vec![
8143                        Ref::keyword("OWNER").to_matchable(),
8144                        Ref::keyword("TO").to_matchable(),
8145                        one_of(vec![
8146                            one_of(vec![
8147                                Ref::new("ParameterNameSegment").to_matchable(),
8148                                Ref::new("QuotedIdentifierSegment").to_matchable(),
8149                            ])
8150                            .to_matchable(),
8151                            Ref::keyword("CURRENT_ROLE").to_matchable(),
8152                            Ref::keyword("CURRENT_USER").to_matchable(),
8153                            Ref::keyword("SESSION_USER").to_matchable(),
8154                        ])
8155                        .to_matchable(),
8156                    ])
8157                    .to_matchable(),
8158                    Sequence::new(vec![
8159                        Ref::keyword("RENAME").to_matchable(),
8160                        Ref::keyword("TO").to_matchable(),
8161                        Ref::new("StatisticsReferenceSegment").to_matchable(),
8162                    ])
8163                    .to_matchable(),
8164                    Sequence::new(vec![
8165                        Ref::keyword("SET").to_matchable(),
8166                        one_of(vec![
8167                            Sequence::new(vec![
8168                                Ref::keyword("SCHEMA").to_matchable(),
8169                                Ref::new("SchemaReferenceSegment").to_matchable(),
8170                            ])
8171                            .to_matchable(),
8172                            Sequence::new(vec![
8173                                Ref::keyword("STATISTICS").to_matchable(),
8174                                Ref::new("NumericLiteralSegment").to_matchable(),
8175                            ])
8176                            .to_matchable(),
8177                        ])
8178                        .to_matchable(),
8179                    ])
8180                    .to_matchable(),
8181                ])
8182                .to_matchable(),
8183            ])
8184            .to_matchable()
8185            .into(),
8186        ),
8187        (
8188            // Drop Statistics Segment.
8189            // As specified in https://www.postgresql.org/docs/16/sql-dropstatistics.html
8190            "DropStatisticsStatementSegment".into(),
8191            Sequence::new(vec![
8192                Ref::keyword("DROP").to_matchable(),
8193                Ref::keyword("STATISTICS").to_matchable(),
8194                Ref::new("IfExistsGrammar").optional().to_matchable(),
8195                Delimited::new(vec![Ref::new("StatisticsReferenceSegment").to_matchable()])
8196                    .to_matchable(),
8197                one_of(vec![
8198                    Ref::keyword("CASCADE").to_matchable(),
8199                    Ref::keyword("RESTRICT").to_matchable(),
8200                ])
8201                .config(|this| this.optional())
8202                .to_matchable(),
8203            ])
8204            .to_matchable()
8205            .into(),
8206        ),
8207        (
8208            "AccessStatementSegmentGrantRoleWithOptionGrammar".into(),
8209            one_of(vec![
8210                Sequence::new(vec![
8211                    Ref::keyword("WITH").to_matchable(),
8212                    Ref::keyword("GRANT").to_matchable(),
8213                    Ref::keyword("OPTION").to_matchable(),
8214                ])
8215                .to_matchable(),
8216                Sequence::new(vec![
8217                    Ref::keyword("WITH").to_matchable(),
8218                    Ref::keyword("ADMIN").to_matchable(),
8219                    Ref::keyword("OPTION").to_matchable(),
8220                ])
8221                .to_matchable(),
8222                Sequence::new(vec![
8223                    Ref::keyword("WITH").to_matchable(),
8224                    Ref::keyword("ADMIN").to_matchable(),
8225                    Ref::new("BooleanLiteralGrammar").to_matchable(),
8226                ])
8227                .to_matchable(),
8228                Sequence::new(vec![
8229                    Ref::keyword("COPY").to_matchable(),
8230                    Ref::keyword("CURRENT").to_matchable(),
8231                    Ref::keyword("GRANTS").to_matchable(),
8232                ])
8233                .to_matchable(),
8234            ])
8235            .to_matchable()
8236            .into(),
8237        ),
8238    ]);
8239
8240    postgres
8241}
8242
8243pub fn statement_segment() -> Matchable {
8244    ansi::statement_segment().copy(
8245        Some(vec![
8246            Ref::new("CreateStatisticsStatementSegment").to_matchable(),
8247            Ref::new("AlterStatisticsStatementSegment").to_matchable(),
8248            Ref::new("DropStatisticsStatementSegment").to_matchable(),
8249            Ref::new("AlterDefaultPrivilegesStatementSegment").to_matchable(),
8250            Ref::new("DropOwnedStatementSegment").to_matchable(),
8251            Ref::new("ReassignOwnedStatementSegment").to_matchable(),
8252            Ref::new("CommentOnStatementSegment").to_matchable(),
8253            Ref::new("AnalyzeStatementSegment").to_matchable(),
8254            Ref::new("CreateTableAsStatementSegment").to_matchable(),
8255            Ref::new("AlterTriggerStatementSegment").to_matchable(),
8256            Ref::new("AlterAggregateStatementSegment").to_matchable(),
8257            Ref::new("SetStatementSegment").to_matchable(),
8258            Ref::new("AlterPolicyStatementSegment").to_matchable(),
8259            Ref::new("CreatePolicyStatementSegment").to_matchable(),
8260            Ref::new("DropPolicyStatementSegment").to_matchable(),
8261            Ref::new("CreateDomainStatementSegment").to_matchable(),
8262            Ref::new("AlterDomainStatementSegment").to_matchable(),
8263            Ref::new("DropDomainStatementSegment").to_matchable(),
8264            Ref::new("CreateMaterializedViewStatementSegment").to_matchable(),
8265            Ref::new("AlterMaterializedViewStatementSegment").to_matchable(),
8266            Ref::new("DropMaterializedViewStatementSegment").to_matchable(),
8267            Ref::new("RefreshMaterializedViewStatementSegment").to_matchable(),
8268            Ref::new("AlterDatabaseStatementSegment").to_matchable(),
8269            Ref::new("DropDatabaseStatementSegment").to_matchable(),
8270            Ref::new("VacuumStatementSegment").to_matchable(),
8271            Ref::new("AlterFunctionStatementSegment").to_matchable(),
8272            Ref::new("CreateViewStatementSegment").to_matchable(),
8273            Ref::new("AlterViewStatementSegment").to_matchable(),
8274            Ref::new("ListenStatementSegment").to_matchable(),
8275            Ref::new("NotifyStatementSegment").to_matchable(),
8276            Ref::new("UnlistenStatementSegment").to_matchable(),
8277            Ref::new("LoadStatementSegment").to_matchable(),
8278            Ref::new("ResetStatementSegment").to_matchable(),
8279            Ref::new("DiscardStatementSegment").to_matchable(),
8280            Ref::new("AlterProcedureStatementSegment").to_matchable(),
8281            Ref::new("CreateProcedureStatementSegment").to_matchable(),
8282            Ref::new("DropProcedureStatementSegment").to_matchable(),
8283            Ref::new("CopyStatementSegment").to_matchable(),
8284            Ref::new("DoStatementSegment").to_matchable(),
8285            Ref::new("AlterIndexStatementSegment").to_matchable(),
8286            Ref::new("ReindexStatementSegment").to_matchable(),
8287            Ref::new("AlterRoleStatementSegment").to_matchable(),
8288            Ref::new("CreateExtensionStatementSegment").to_matchable(),
8289            Ref::new("DropExtensionStatementSegment").to_matchable(),
8290            Ref::new("CreatePublicationStatementSegment").to_matchable(),
8291            Ref::new("AlterPublicationStatementSegment").to_matchable(),
8292            Ref::new("DropPublicationStatementSegment").to_matchable(),
8293            Ref::new("CreateTypeStatementSegment").to_matchable(),
8294            Ref::new("AlterTypeStatementSegment").to_matchable(),
8295            Ref::new("AlterSchemaStatementSegment").to_matchable(),
8296            Ref::new("LockTableStatementSegment").to_matchable(),
8297            Ref::new("ClusterStatementSegment").to_matchable(),
8298            Ref::new("CreateCollationStatementSegment").to_matchable(),
8299            Ref::new("CallStoredProcedureSegment").to_matchable(),
8300            Ref::new("CreateServerStatementSegment").to_matchable(),
8301            Ref::new("CreateUserMappingStatementSegment").to_matchable(),
8302            Ref::new("ImportForeignSchemaStatementSegment").to_matchable(),
8303        ]),
8304        None,
8305        None,
8306        None,
8307        vec![],
8308        false,
8309    )
8310}