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