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