Skip to main content

sqruff_lib_dialects/
redshift.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, Nothing, Ref};
12use sqruff_lib_core::parser::lexer::Matcher;
13use sqruff_lib_core::parser::matchable::MatchableTrait;
14use sqruff_lib_core::parser::node_matcher::NodeMatcher;
15use sqruff_lib_core::parser::parsers::RegexParser;
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 crate::redshift_keywords::{REDSHIFT_RESERVED_KEYWORDS, REDSHIFT_UNRESERVED_KEYWORDS};
21use sqruff_lib_core::dialects::init::DialectConfig;
22use sqruff_lib_core::value::Value;
23
24sqruff_lib_core::dialect_config!(RedshiftDialectConfig {});
25
26pub fn dialect(config: Option<&Value>) -> Dialect {
27    // Parse and validate dialect configuration, falling back to defaults on failure
28    let _dialect_config: RedshiftDialectConfig = config
29        .map(RedshiftDialectConfig::from_value)
30        .unwrap_or_default();
31
32    raw_dialect().config(|this| this.expand())
33}
34
35pub fn raw_dialect() -> Dialect {
36    let postgres_dialect = super::postgres::raw_dialect();
37    let ansi_dialect = super::ansi::raw_dialect();
38    let mut redshift_dialect = postgres_dialect.clone();
39    redshift_dialect.name = DialectKind::Redshift;
40
41    redshift_dialect.sets_mut("unreserved_keywords").clear();
42    redshift_dialect.update_keywords_set_from_multiline_string(
43        "unreserved_keywords",
44        REDSHIFT_UNRESERVED_KEYWORDS,
45    );
46    redshift_dialect.sets_mut("reserved_keywords").clear();
47    redshift_dialect
48        .update_keywords_set_from_multiline_string("reserved_keywords", REDSHIFT_RESERVED_KEYWORDS);
49    redshift_dialect.sets_mut("bare_functions").clear();
50    redshift_dialect.sets_mut("bare_functions").extend([
51        "current_date",
52        "sysdate",
53        "current_time",
54        "current_timestamp",
55        "user",
56        "current_user",
57        "current_aws_account",
58        "current_namespace",
59        "current_user_id",
60    ]);
61    redshift_dialect
62        .sets_mut("date_part_function_name")
63        .extend(["DATEADD", "DATEDIFF", "EXTRACT", "DATE_PART"]);
64    redshift_dialect.sets_mut("datetime_units").extend([
65        "MILLENNIUM",
66        "MILLENNIA",
67        "MIL",
68        "MILS",
69        "CENTURY",
70        "CENTURIES",
71        "C",
72        "CENT",
73        "CENTS",
74        "DECADE",
75        "DECADES",
76        "DEC",
77        "DECS",
78        "EPOCH",
79        "YEAR",
80        "YEARS",
81        "Y",
82        "YR",
83        "YRS",
84        "QUARTER",
85        "QUARTERS",
86        "QTR",
87        "QTRS",
88        "MONTH",
89        "MONTHS",
90        "MON",
91        "MONS",
92        "WEEK",
93        "WEEKS",
94        "W",
95        "DAYOFWEEK",
96        "DOW",
97        "DW",
98        "WEEKDAY",
99        "DAYOFYEAR",
100        "DOY",
101        "DY",
102        "YEARDAY",
103        "DAY",
104        "DAYS",
105        "D",
106        "HOUR",
107        "HOURS",
108        "H",
109        "HR",
110        "HRS",
111        "MINUTE",
112        "MINUTES",
113        "M",
114        "MIN",
115        "MINS",
116        "SECOND",
117        "SECONDS",
118        "S",
119        "SEC",
120        "SECS",
121        "MILLISECOND",
122        "MILLISECONDS",
123        "MS",
124        "MSEC",
125        "MSECS",
126        "MSECOND",
127        "MSECONDS",
128        "MILLISEC",
129        "MILLISECS",
130        "MILLISECON",
131        "MICROSECOND",
132        "MICROSECONDS",
133        "MICROSEC",
134        "MICROSECS",
135        "MICROSECOND",
136        "USECOND",
137        "USECONDS",
138        "US",
139        "USEC",
140        "USECS",
141        "TIMEZONE",
142        "TIMEZONE_HOUR",
143        "TIMEZONE_MINUTE",
144    ]);
145    redshift_dialect.add([
146        (
147            "WellKnownTextGeometrySegment".into(),
148            Nothing::new().to_matchable().into(),
149        ),
150        (
151            "JoinLikeClauseGrammar".into(),
152            Sequence::new(vec![
153                any_set_of(vec![
154                    Ref::new("FromPivotExpressionSegment").to_matchable(),
155                    Ref::new("FromUnpivotExpressionSegment").to_matchable(),
156                ])
157                .config(|this| {
158                    this.min_times = 1;
159                })
160                .to_matchable(),
161                Ref::new("AliasExpressionSegment").optional().to_matchable(),
162            ])
163            .to_matchable()
164            .into(),
165        ),
166        (
167            "NakedIdentifierSegment".into(),
168            SegmentGenerator::new(|dialect| {
169                // Generate the anti template from the set of reserved keywords
170                let reserved_keywords = dialect.sets("reserved_keywords");
171                let pattern = reserved_keywords.iter().join("|");
172                let anti_template = format!("^({pattern})$");
173
174                RegexParser::new(
175                    "#?([A-Z_]+|[0-9]+[A-Z_$])[A-Z0-9_$]*",
176                    SyntaxKind::NakedIdentifier,
177                )
178                .anti_template(&anti_template)
179                .to_matchable()
180            })
181            .into(),
182        ),
183    ]);
184
185    redshift_dialect.patch_lexer_matchers(vec![Matcher::regex(
186        "word",
187        r"#?[0-9a-zA-Z_]+[0-9a-zA-Z_$]*",
188        SyntaxKind::Word,
189    )]);
190
191    redshift_dialect.add([
192        (
193            "CompressionTypeGrammar".into(),
194            one_of(vec![
195                Ref::keyword("BZIP2").to_matchable(),
196                Ref::keyword("GZIP").to_matchable(),
197                Ref::keyword("LZOP").to_matchable(),
198                Ref::keyword("ZSTD").to_matchable(),
199            ])
200            .to_matchable()
201            .into(),
202        ),
203        (
204            "ArgModeGrammar".into(),
205            one_of(vec![
206                Ref::keyword("IN").to_matchable(),
207                Ref::keyword("OUT").to_matchable(),
208                Ref::keyword("INOUT").to_matchable(),
209            ])
210            .to_matchable()
211            .into(),
212        ),
213        (
214            "ColumnEncodingGrammar".into(),
215            one_of(vec![
216                Ref::keyword("RAW").to_matchable(),
217                Ref::keyword("AZ64").to_matchable(),
218                Ref::keyword("BYTEDICT").to_matchable(),
219                Ref::keyword("DELTA").to_matchable(),
220                Ref::keyword("DELTA32K").to_matchable(),
221                Ref::keyword("LZO").to_matchable(),
222                Ref::keyword("MOSTLY8").to_matchable(),
223                Ref::keyword("MOSTLY16").to_matchable(),
224                Ref::keyword("MOSTLY32").to_matchable(),
225                Ref::keyword("RUNLENGTH").to_matchable(),
226                Ref::keyword("TEXT255").to_matchable(),
227                Ref::keyword("TEXT32K").to_matchable(),
228                Ref::keyword("ZSTD").to_matchable(),
229            ])
230            .to_matchable()
231            .into(),
232        ),
233        (
234            "QuotaGrammar".into(),
235            Sequence::new(vec![
236                Ref::keyword("QUOTA").to_matchable(),
237                one_of(vec![
238                    Sequence::new(vec![
239                        Ref::new("NumericLiteralSegment").to_matchable(),
240                        one_of(vec![
241                            Ref::keyword("MB").to_matchable(),
242                            Ref::keyword("GB").to_matchable(),
243                            Ref::keyword("TB").to_matchable(),
244                        ])
245                        .to_matchable(),
246                    ])
247                    .to_matchable(),
248                    Ref::keyword("UNLIMITED").to_matchable(),
249                ])
250                .to_matchable(),
251            ])
252            .to_matchable()
253            .into(),
254        ),
255    ]);
256
257    redshift_dialect.add([
258        (
259            "FromUnpivotExpressionSegment".into(),
260            NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_| {
261                Sequence::new(vec![
262                    Ref::keyword("UNPIVOT").to_matchable(),
263                    Sequence::new(vec![
264                        one_of(vec![
265                            Ref::keyword("INCLUDE").to_matchable(),
266                            Ref::keyword("EXCLUDE").to_matchable(),
267                        ])
268                        .to_matchable(),
269                        Ref::keyword("NULLS").to_matchable(),
270                    ])
271                    .config(|this| {
272                        this.optional();
273                    })
274                    .to_matchable(),
275                    Bracketed::new(vec![
276                        Sequence::new(vec![
277                            Ref::new("ColumnReferenceSegment").to_matchable(),
278                            Ref::keyword("FOR").to_matchable(),
279                            Ref::new("ColumnReferenceSegment").to_matchable(),
280                            Ref::keyword("IN").to_matchable(),
281                            Bracketed::new(vec![
282                                Delimited::new(vec![
283                                    Sequence::new(vec![
284                                        Ref::new("ColumnReferenceSegment").to_matchable(),
285                                        Ref::new("AliasExpressionSegment")
286                                            .optional()
287                                            .to_matchable(),
288                                    ])
289                                    .to_matchable(),
290                                ])
291                                .to_matchable(),
292                            ])
293                            .to_matchable(),
294                        ])
295                        .to_matchable(),
296                    ])
297                    .to_matchable(),
298                ])
299                .to_matchable()
300            })
301            .to_matchable()
302            .into(),
303        ),
304        (
305            "FromPivotExpressionSegment".into(),
306            NodeMatcher::new(SyntaxKind::FromPivotExpression, |_| {
307                Sequence::new(vec![
308                    Ref::keyword("PIVOT").to_matchable(),
309                    Bracketed::new(vec![
310                        Sequence::new(vec![
311                            optionally_bracketed(vec![Ref::new("FunctionSegment").to_matchable()])
312                                .to_matchable(),
313                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
314                            Ref::keyword("FOR").to_matchable(),
315                            Ref::new("ColumnReferenceSegment").to_matchable(),
316                            Ref::keyword("IN").to_matchable(),
317                            Bracketed::new(vec![
318                                Delimited::new(vec![
319                                    Sequence::new(vec![
320                                        Ref::new("ExpressionSegment").to_matchable(),
321                                        Ref::new("AliasExpressionSegment")
322                                            .optional()
323                                            .to_matchable(),
324                                    ])
325                                    .to_matchable(),
326                                ])
327                                .to_matchable(),
328                            ])
329                            .to_matchable(),
330                        ])
331                        .to_matchable(),
332                    ])
333                    .to_matchable(),
334                ])
335                .to_matchable()
336            })
337            .to_matchable()
338            .into(),
339        ),
340        (
341            "DateTimeTypeIdentifier".into(),
342            NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_| {
343                one_of(vec![
344                    Ref::keyword("DATE").to_matchable(),
345                    Ref::keyword("DATETIME").to_matchable(),
346                    Sequence::new(vec![
347                        one_of(vec![
348                            Ref::keyword("TIME").to_matchable(),
349                            Ref::keyword("TIMESTAMP").to_matchable(),
350                        ])
351                        .to_matchable(),
352                        Sequence::new(vec![
353                            one_of(vec![
354                                Ref::keyword("WITH").to_matchable(),
355                                Ref::keyword("WITHOUT").to_matchable(),
356                            ])
357                            .to_matchable(),
358                            Ref::keyword("TIME").to_matchable(),
359                            Ref::keyword("ZONE").to_matchable(),
360                        ])
361                        .config(|this| {
362                            this.optional();
363                        })
364                        .to_matchable(),
365                    ])
366                    .to_matchable(),
367                    one_of(vec![
368                        Ref::keyword("TIMETZ").to_matchable(),
369                        Ref::keyword("TIMESTAMPTZ").to_matchable(),
370                    ])
371                    .to_matchable(),
372                ])
373                .to_matchable()
374            })
375            .to_matchable()
376            .into(),
377        ),
378    ]);
379    redshift_dialect.replace_grammar(
380        "BracketedArguments",
381        Bracketed::new(vec![
382            Delimited::new(vec![
383                one_of(vec![
384                    Ref::new("LiteralGrammar").to_matchable(),
385                    Ref::keyword("MAX").to_matchable(),
386                ])
387                .to_matchable(),
388            ])
389            .config(|this| {
390                this.optional();
391            })
392            .to_matchable(),
393        ])
394        .to_matchable(),
395    );
396
397    redshift_dialect.add([
398        (
399            "DatatypeSegment".into(),
400            NodeMatcher::new(SyntaxKind::DataType, |_| {
401                one_of(vec![
402                    Ref::keyword("SMALLINT").to_matchable(),
403                    Ref::keyword("INT2").to_matchable(),
404                    Ref::keyword("INTEGER").to_matchable(),
405                    Ref::keyword("INT").to_matchable(),
406                    Ref::keyword("INT4").to_matchable(),
407                    Ref::keyword("BIGINT").to_matchable(),
408                    Ref::keyword("INT8").to_matchable(),
409                    Ref::keyword("REAL").to_matchable(),
410                    Ref::keyword("FLOAT4").to_matchable(),
411                    Sequence::new(vec![
412                        Ref::keyword("DOUBLE").to_matchable(),
413                        Ref::keyword("PRECISION").to_matchable(),
414                    ])
415                    .to_matchable(),
416                    Ref::keyword("FLOAT8").to_matchable(),
417                    Ref::keyword("FLOAT").to_matchable(),
418                    Sequence::new(vec![
419                        one_of(vec![
420                            Ref::keyword("DECIMAL").to_matchable(),
421                            Ref::keyword("NUMERIC").to_matchable(),
422                        ])
423                        .to_matchable(),
424                        Ref::new("BracketedArguments").optional().to_matchable(),
425                    ])
426                    .to_matchable(),
427                    one_of(vec![
428                        Sequence::new(vec![
429                            one_of(vec![
430                                Ref::keyword("CHAR").to_matchable(),
431                                Ref::keyword("CHARACTER").to_matchable(),
432                                Ref::keyword("NCHAR").to_matchable(),
433                                Ref::keyword("VARCHAR").to_matchable(),
434                                Sequence::new(vec![
435                                    Ref::keyword("CHARACTER").to_matchable(),
436                                    Ref::keyword("VARYING").to_matchable(),
437                                ])
438                                .to_matchable(),
439                                Ref::keyword("NVARCHAR").to_matchable(),
440                            ])
441                            .to_matchable(),
442                            Ref::new("BracketedArguments").optional().to_matchable(),
443                        ])
444                        .to_matchable(),
445                        Ref::keyword("BPCHAR").to_matchable(),
446                        Ref::keyword("TEXT").to_matchable(),
447                    ])
448                    .to_matchable(),
449                    Ref::new("DateTimeTypeIdentifier").to_matchable(),
450                    Ref::keyword("INTERVAL").to_matchable(),
451                    one_of(vec![
452                        Ref::keyword("BOOLEAN").to_matchable(),
453                        Ref::keyword("BOOL").to_matchable(),
454                    ])
455                    .to_matchable(),
456                    Ref::keyword("HLLSKETCH").to_matchable(),
457                    Ref::keyword("SUPER").to_matchable(),
458                    Ref::keyword("GEOMETRY").to_matchable(),
459                    Ref::keyword("GEOGRAPHY").to_matchable(),
460                    Sequence::new(vec![
461                        one_of(vec![
462                            Ref::keyword("VARBYTE").to_matchable(),
463                            Ref::keyword("VARBINARY").to_matchable(),
464                            Sequence::new(vec![
465                                Ref::keyword("BINARY").to_matchable(),
466                                Ref::keyword("VARYING").to_matchable(),
467                            ])
468                            .to_matchable(),
469                        ])
470                        .to_matchable(),
471                        Ref::new("BracketedArguments").optional().to_matchable(),
472                    ])
473                    .to_matchable(),
474                    Ref::keyword("ANYELEMENT").to_matchable(),
475                ])
476                .to_matchable()
477            })
478            .to_matchable()
479            .into(),
480        ),
481        (
482            "DataFormatSegment".into(),
483            NodeMatcher::new(SyntaxKind::DataFormatSegment, |_| {
484                Sequence::new(vec![
485                    Sequence::new(vec![
486                        Ref::keyword("FORMAT").to_matchable(),
487                        Ref::keyword("AS").optional().to_matchable(),
488                    ])
489                    .config(|this| {
490                        this.optional();
491                    })
492                    .to_matchable(),
493                    one_of(vec![
494                        Sequence::new(vec![
495                            Ref::keyword("CSV").to_matchable(),
496                            Sequence::new(vec![
497                                Ref::keyword("QUOTE").to_matchable(),
498                                Ref::keyword("AS").optional().to_matchable(),
499                                Ref::new("QuotedLiteralSegment").to_matchable(),
500                            ])
501                            .config(|this| {
502                                this.optional();
503                            })
504                            .to_matchable(),
505                        ])
506                        .to_matchable(),
507                        Sequence::new(vec![
508                            Ref::keyword("SHAPEFILE").to_matchable(),
509                            Sequence::new(vec![
510                                Ref::keyword("SIMPLIFY").to_matchable(),
511                                Ref::keyword("AUTO").optional().to_matchable(),
512                                Ref::new("NumericLiteralSegment").optional().to_matchable(),
513                            ])
514                            .config(|this| {
515                                this.optional();
516                            })
517                            .to_matchable(),
518                        ])
519                        .to_matchable(),
520                        Sequence::new(vec![
521                            one_of(vec![
522                                Ref::keyword("AVRO").to_matchable(),
523                                Ref::keyword("JSON").to_matchable(),
524                            ])
525                            .to_matchable(),
526                            Sequence::new(vec![
527                                Ref::keyword("AS").optional().to_matchable(),
528                                Ref::new("QuotedLiteralSegment").to_matchable(),
529                            ])
530                            .config(|this| {
531                                this.optional();
532                            })
533                            .to_matchable(),
534                        ])
535                        .to_matchable(),
536                        Ref::keyword("PARQUET").to_matchable(),
537                        Ref::keyword("ORC").to_matchable(),
538                        Ref::keyword("RCFILE").to_matchable(),
539                        Ref::keyword("SEQUENCEFILE").to_matchable(),
540                    ])
541                    .to_matchable(),
542                ])
543                .to_matchable()
544            })
545            .to_matchable()
546            .into(),
547        ),
548        (
549            "AuthorizationSegment".into(),
550            NodeMatcher::new(SyntaxKind::AuthorizationSegment, |_| {
551                any_set_of(vec![
552                    one_of(vec![
553                        Sequence::new(vec![
554                            Ref::keyword("IAM_ROLE").to_matchable(),
555                            one_of(vec![
556                                Ref::keyword("DEFAULT").to_matchable(),
557                                Ref::new("QuotedLiteralSegment").to_matchable(),
558                            ])
559                            .to_matchable(),
560                        ])
561                        .to_matchable(),
562                        Sequence::new(vec![
563                            Ref::keyword("WITH").optional().to_matchable(),
564                            Ref::keyword("CREDENTIALS").to_matchable(),
565                            Ref::keyword("AS").optional().to_matchable(),
566                            Ref::new("QuotedLiteralSegment").to_matchable(),
567                        ])
568                        .to_matchable(),
569                        Sequence::new(vec![
570                            Ref::keyword("ACCESS_KEY_ID").to_matchable(),
571                            Ref::new("QuotedLiteralSegment").to_matchable(),
572                            Ref::keyword("SECRET_ACCESS_KEY").to_matchable(),
573                            Ref::new("QuotedLiteralSegment").to_matchable(),
574                            Sequence::new(vec![
575                                Ref::keyword("SESSION_TOKEN").to_matchable(),
576                                Ref::new("QuotedLiteralSegment").to_matchable(),
577                            ])
578                            .config(|this| {
579                                this.optional();
580                            })
581                            .to_matchable(),
582                        ])
583                        .to_matchable(),
584                    ])
585                    .to_matchable(),
586                    Sequence::new(vec![
587                        Ref::keyword("KMS_KEY_ID").to_matchable(),
588                        Ref::new("QuotedLiteralSegment").to_matchable(),
589                    ])
590                    .config(|this| {
591                        this.optional();
592                    })
593                    .to_matchable(),
594                    Sequence::new(vec![
595                        Ref::keyword("MASTER_SYMMETRIC_KEY").to_matchable(),
596                        Ref::new("QuotedLiteralSegment").to_matchable(),
597                    ])
598                    .config(|this| {
599                        this.optional();
600                    })
601                    .to_matchable(),
602                ])
603                .to_matchable()
604            })
605            .to_matchable()
606            .into(),
607        ),
608        (
609            "ColumnAttributeSegment".into(),
610            NodeMatcher::new(SyntaxKind::ColumnAttributeSegment, |_| {
611                any_set_of(vec![
612                    Sequence::new(vec![
613                        Ref::keyword("DEFAULT").to_matchable(),
614                        Ref::new("ExpressionSegment").to_matchable(),
615                    ])
616                    .to_matchable(),
617                    Sequence::new(vec![
618                        Ref::keyword("IDENTITY").to_matchable(),
619                        Bracketed::new(vec![
620                            Delimited::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
621                                .to_matchable(),
622                        ])
623                        .config(|this| {
624                            this.optional();
625                        })
626                        .to_matchable(),
627                    ])
628                    .to_matchable(),
629                    Sequence::new(vec![
630                        Ref::keyword("GENERATED").to_matchable(),
631                        Ref::keyword("BY").to_matchable(),
632                        Ref::keyword("DEFAULT").to_matchable(),
633                        Ref::keyword("AS").to_matchable(),
634                        Ref::keyword("IDENTITY").to_matchable(),
635                        Bracketed::new(vec![
636                            Delimited::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
637                                .to_matchable(),
638                        ])
639                        .config(|this| {
640                            this.optional();
641                        })
642                        .to_matchable(),
643                    ])
644                    .to_matchable(),
645                    Sequence::new(vec![
646                        Ref::keyword("ENCODE").to_matchable(),
647                        Ref::new("ColumnEncodingGrammar").to_matchable(),
648                    ])
649                    .to_matchable(),
650                    Ref::keyword("DISTKEY").to_matchable(),
651                    Ref::keyword("SORTKEY").to_matchable(),
652                    Sequence::new(vec![
653                        Ref::keyword("COLLATE").to_matchable(),
654                        one_of(vec![
655                            Ref::keyword("CASE_SENSITIVE").to_matchable(),
656                            Ref::keyword("CASE_INSENSITIVE").to_matchable(),
657                        ])
658                        .to_matchable(),
659                    ])
660                    .to_matchable(),
661                ])
662                .to_matchable()
663            })
664            .to_matchable()
665            .into(),
666        ),
667        (
668            "ColumnConstraintSegment".into(),
669            NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_| {
670                any_set_of(vec![
671                    one_of(vec![
672                        Sequence::new(vec![
673                            Ref::keyword("NOT").to_matchable(),
674                            Ref::keyword("NULL").to_matchable(),
675                        ])
676                        .to_matchable(),
677                        Ref::keyword("NULL").to_matchable(),
678                    ])
679                    .to_matchable(),
680                    one_of(vec![
681                        Ref::keyword("UNIQUE").to_matchable(),
682                        Ref::new("PrimaryKeyGrammar").to_matchable(),
683                    ])
684                    .to_matchable(),
685                    Sequence::new(vec![
686                        Ref::keyword("REFERENCES").to_matchable(),
687                        Ref::new("TableReferenceSegment").to_matchable(),
688                        Bracketed::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
689                            .config(|this| {
690                                this.optional();
691                            })
692                            .to_matchable(),
693                    ])
694                    .to_matchable(),
695                ])
696                .to_matchable()
697            })
698            .to_matchable()
699            .into(),
700        ),
701        (
702            "AlterTableActionSegment".into(),
703            NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_| {
704                one_of(vec![
705                    Sequence::new(vec![
706                        Ref::keyword("ADD").to_matchable(),
707                        Ref::new("TableConstraintSegment").to_matchable(),
708                        Sequence::new(vec![
709                            Ref::keyword("NOT").to_matchable(),
710                            Ref::keyword("VALID").to_matchable(),
711                        ])
712                        .config(|this| {
713                            this.optional();
714                        })
715                        .to_matchable(),
716                    ])
717                    .to_matchable(),
718                    Sequence::new(vec![
719                        Ref::keyword("VALIDATE").to_matchable(),
720                        Ref::keyword("CONSTRAINT").to_matchable(),
721                        Ref::new("ParameterNameSegment").to_matchable(),
722                    ])
723                    .to_matchable(),
724                    Sequence::new(vec![
725                        Ref::keyword("DROP").to_matchable(),
726                        Ref::keyword("CONSTRAINT").to_matchable(),
727                        Ref::new("ParameterNameSegment").to_matchable(),
728                        Ref::new("DropBehaviorGrammar").optional().to_matchable(),
729                    ])
730                    .to_matchable(),
731                    Sequence::new(vec![
732                        Ref::keyword("OWNER").to_matchable(),
733                        Ref::keyword("TO").to_matchable(),
734                        one_of(vec![
735                            one_of(vec![
736                                Ref::new("ParameterNameSegment").to_matchable(),
737                                Ref::new("QuotedIdentifierSegment").to_matchable(),
738                            ])
739                            .to_matchable(),
740                        ])
741                        .to_matchable(),
742                    ])
743                    .to_matchable(),
744                    Sequence::new(vec![
745                        Ref::keyword("RENAME").to_matchable(),
746                        Ref::keyword("TO").to_matchable(),
747                        one_of(vec![
748                            one_of(vec![
749                                Ref::new("ParameterNameSegment").to_matchable(),
750                                Ref::new("QuotedIdentifierSegment").to_matchable(),
751                            ])
752                            .to_matchable(),
753                        ])
754                        .to_matchable(),
755                    ])
756                    .to_matchable(),
757                    Sequence::new(vec![
758                        Ref::keyword("RENAME").to_matchable(),
759                        Ref::keyword("COLUMN").to_matchable(),
760                        Ref::keyword("TO").to_matchable(),
761                        one_of(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
762                            .to_matchable(),
763                    ])
764                    .to_matchable(),
765                    Sequence::new(vec![
766                        Ref::keyword("ALTER").to_matchable(),
767                        Ref::keyword("COLUMN").optional().to_matchable(),
768                        Ref::new("ColumnReferenceSegment").to_matchable(),
769                        one_of(vec![
770                            Sequence::new(vec![
771                                Ref::keyword("TYPE").to_matchable(),
772                                Ref::new("DatatypeSegment").to_matchable(),
773                            ])
774                            .to_matchable(),
775                            Sequence::new(vec![
776                                Ref::keyword("ENCODE").to_matchable(),
777                                Delimited::new(vec![
778                                    Ref::new("ColumnEncodingGrammar").to_matchable(),
779                                ])
780                                .to_matchable(),
781                            ])
782                            .to_matchable(),
783                        ])
784                        .to_matchable(),
785                    ])
786                    .to_matchable(),
787                    Sequence::new(vec![
788                        Ref::keyword("ALTER").to_matchable(),
789                        Ref::keyword("DISTKEY").to_matchable(),
790                        Ref::new("ColumnReferenceSegment").to_matchable(),
791                    ])
792                    .to_matchable(),
793                    Sequence::new(vec![
794                        Ref::keyword("ALTER").to_matchable(),
795                        Ref::keyword("DISTSTYLE").to_matchable(),
796                        one_of(vec![
797                            Ref::keyword("ALL").to_matchable(),
798                            Ref::keyword("EVEN").to_matchable(),
799                            Sequence::new(vec![
800                                Ref::keyword("KEY").to_matchable(),
801                                Ref::keyword("DISTKEY").to_matchable(),
802                                Ref::new("ColumnReferenceSegment").to_matchable(),
803                            ])
804                            .to_matchable(),
805                            Ref::keyword("AUTO").to_matchable(),
806                        ])
807                        .to_matchable(),
808                    ])
809                    .to_matchable(),
810                    Sequence::new(vec![
811                        Ref::keyword("ALTER").to_matchable(),
812                        Ref::keyword("COMPOUND").optional().to_matchable(),
813                        Ref::keyword("SORTKEY").to_matchable(),
814                        Bracketed::new(vec![
815                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
816                                .to_matchable(),
817                        ])
818                        .to_matchable(),
819                    ])
820                    .to_matchable(),
821                    Sequence::new(vec![
822                        Ref::keyword("ALTER").to_matchable(),
823                        Ref::keyword("SORTKEY").to_matchable(),
824                        one_of(vec![
825                            Ref::keyword("AUTO").to_matchable(),
826                            Ref::keyword("NONE").to_matchable(),
827                        ])
828                        .to_matchable(),
829                    ])
830                    .to_matchable(),
831                    Sequence::new(vec![
832                        Ref::keyword("ALTER").to_matchable(),
833                        Ref::keyword("ENCODE").to_matchable(),
834                        Ref::keyword("AUTO").to_matchable(),
835                    ])
836                    .to_matchable(),
837                    Sequence::new(vec![
838                        Ref::keyword("ADD").to_matchable(),
839                        Ref::keyword("COLUMN").optional().to_matchable(),
840                        Ref::new("ColumnReferenceSegment").to_matchable(),
841                        Ref::new("DatatypeSegment").to_matchable(),
842                        Sequence::new(vec![
843                            Ref::keyword("DEFAULT").to_matchable(),
844                            Ref::new("ExpressionSegment").to_matchable(),
845                        ])
846                        .config(|this| {
847                            this.optional();
848                        })
849                        .to_matchable(),
850                        Sequence::new(vec![
851                            Ref::keyword("COLLATE").to_matchable(),
852                            Ref::new("CollationReferenceSegment").to_matchable(),
853                        ])
854                        .config(|this| {
855                            this.optional();
856                        })
857                        .to_matchable(),
858                        AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()])
859                            .to_matchable(),
860                    ])
861                    .to_matchable(),
862                    Sequence::new(vec![
863                        Ref::keyword("DROP").to_matchable(),
864                        Ref::keyword("COLUMN").optional().to_matchable(),
865                        Ref::new("ColumnReferenceSegment").to_matchable(),
866                        Ref::new("DropBehaviorGrammar").optional().to_matchable(),
867                    ])
868                    .to_matchable(),
869                ])
870                .to_matchable()
871            })
872            .to_matchable()
873            .into(),
874        ),
875        (
876            "TableAttributeSegment".into(),
877            NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
878                any_set_of(vec![
879                    Sequence::new(vec![
880                        Ref::keyword("DISTSTYLE").to_matchable(),
881                        one_of(vec![
882                            Ref::keyword("AUTO").to_matchable(),
883                            Ref::keyword("EVEN").to_matchable(),
884                            Ref::keyword("KEY").to_matchable(),
885                            Ref::keyword("ALL").to_matchable(),
886                        ])
887                        .to_matchable(),
888                    ])
889                    .config(|this| {
890                        this.optional();
891                    })
892                    .to_matchable(),
893                    Sequence::new(vec![
894                        Ref::keyword("DISTKEY").to_matchable(),
895                        Bracketed::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
896                            .to_matchable(),
897                    ])
898                    .config(|this| {
899                        this.optional();
900                    })
901                    .to_matchable(),
902                    one_of(vec![
903                        Sequence::new(vec![
904                            one_of(vec![
905                                Ref::keyword("COMPOUND").to_matchable(),
906                                Ref::keyword("INTERLEAVED").to_matchable(),
907                            ])
908                            .config(|this| {
909                                this.optional();
910                            })
911                            .to_matchable(),
912                            Ref::keyword("SORTKEY").to_matchable(),
913                            Bracketed::new(vec![
914                                Delimited::new(vec![
915                                    Ref::new("ColumnReferenceSegment").to_matchable(),
916                                ])
917                                .to_matchable(),
918                            ])
919                            .to_matchable(),
920                        ])
921                        .to_matchable(),
922                        Sequence::new(vec![
923                            Ref::keyword("SORTKEY").to_matchable(),
924                            Ref::keyword("AUTO").to_matchable(),
925                        ])
926                        .to_matchable(),
927                    ])
928                    .config(|this| {
929                        this.optional();
930                    })
931                    .to_matchable(),
932                    Sequence::new(vec![
933                        Ref::keyword("ENCODE").to_matchable(),
934                        Ref::keyword("AUTO").to_matchable(),
935                    ])
936                    .config(|this| {
937                        this.optional();
938                    })
939                    .to_matchable(),
940                ])
941                .to_matchable()
942            })
943            .to_matchable()
944            .into(),
945        ),
946        (
947            "TableConstraintSegment".into(),
948            NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
949                Sequence::new(vec![
950                    Sequence::new(vec![
951                        Ref::keyword("CONSTRAINT").to_matchable(),
952                        Ref::new("ObjectReferenceSegment").to_matchable(),
953                    ])
954                    .config(|this| {
955                        this.optional();
956                    })
957                    .to_matchable(),
958                    one_of(vec![
959                        Sequence::new(vec![
960                            Ref::keyword("UNIQUE").to_matchable(),
961                            Bracketed::new(vec![
962                                Delimited::new(vec![
963                                    Ref::new("ColumnReferenceSegment").to_matchable(),
964                                ])
965                                .to_matchable(),
966                            ])
967                            .to_matchable(),
968                        ])
969                        .to_matchable(),
970                        Sequence::new(vec![
971                            Ref::keyword("PRIMARY").to_matchable(),
972                            Ref::keyword("KEY").to_matchable(),
973                            Bracketed::new(vec![
974                                Delimited::new(vec![
975                                    Ref::new("ColumnReferenceSegment").to_matchable(),
976                                ])
977                                .to_matchable(),
978                            ])
979                            .to_matchable(),
980                        ])
981                        .to_matchable(),
982                        Sequence::new(vec![
983                            Ref::keyword("FOREIGN").to_matchable(),
984                            Ref::keyword("KEY").to_matchable(),
985                            Bracketed::new(vec![
986                                Delimited::new(vec![
987                                    Ref::new("ColumnReferenceSegment").to_matchable(),
988                                ])
989                                .to_matchable(),
990                            ])
991                            .to_matchable(),
992                            Ref::keyword("REFERENCES").to_matchable(),
993                            Ref::new("TableReferenceSegment").to_matchable(),
994                            Sequence::new(vec![
995                                Bracketed::new(vec![
996                                    Ref::new("ColumnReferenceSegment").to_matchable(),
997                                ])
998                                .to_matchable(),
999                            ])
1000                            .to_matchable(),
1001                        ])
1002                        .to_matchable(),
1003                    ])
1004                    .to_matchable(),
1005                ])
1006                .to_matchable()
1007            })
1008            .to_matchable()
1009            .into(),
1010        ),
1011        (
1012            "LikeOptionSegment".into(),
1013            NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_| {
1014                Sequence::new(vec![
1015                    one_of(vec![
1016                        Ref::keyword("INCLUDING").to_matchable(),
1017                        Ref::keyword("EXCLUDING").to_matchable(),
1018                    ])
1019                    .to_matchable(),
1020                    Ref::keyword("DEFAULTS").to_matchable(),
1021                ])
1022                .to_matchable()
1023            })
1024            .to_matchable()
1025            .into(),
1026        ),
1027        (
1028            "CreateTableStatementSegment".into(),
1029            NodeMatcher::new(SyntaxKind::CreateTableStatement, |_| {
1030                Sequence::new(vec![
1031                    Ref::keyword("CREATE").to_matchable(),
1032                    Ref::keyword("LOCAL").optional().to_matchable(),
1033                    Ref::new("TemporaryGrammar").optional().to_matchable(),
1034                    Ref::keyword("TABLE").to_matchable(),
1035                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1036                    Ref::new("TableReferenceSegment").to_matchable(),
1037                    Bracketed::new(vec![
1038                        Delimited::new(vec![
1039                            AnyNumberOf::new(vec![
1040                                Sequence::new(vec![
1041                                    Ref::new("ColumnReferenceSegment").to_matchable(),
1042                                    Ref::new("DatatypeSegment").to_matchable(),
1043                                    AnyNumberOf::new(vec![
1044                                        Ref::new("ColumnAttributeSegment").to_matchable(),
1045                                        Ref::new("ColumnConstraintSegment").to_matchable(),
1046                                    ])
1047                                    .config(|this| {
1048                                        this.optional();
1049                                    })
1050                                    .to_matchable(),
1051                                ])
1052                                .to_matchable(),
1053                                Ref::new("TableConstraintSegment").to_matchable(),
1054                                Sequence::new(vec![
1055                                    Ref::keyword("LIKE").to_matchable(),
1056                                    Ref::new("TableReferenceSegment").to_matchable(),
1057                                    AnyNumberOf::new(vec![
1058                                        Ref::new("LikeOptionSegment").to_matchable(),
1059                                    ])
1060                                    .config(|this| {
1061                                        this.optional();
1062                                    })
1063                                    .to_matchable(),
1064                                ])
1065                                .to_matchable(),
1066                            ])
1067                            .to_matchable(),
1068                        ])
1069                        .to_matchable(),
1070                    ])
1071                    .to_matchable(),
1072                    Sequence::new(vec![
1073                        Ref::keyword("BACKUP").to_matchable(),
1074                        one_of(vec![
1075                            Ref::keyword("YES").to_matchable(),
1076                            Ref::keyword("NO").to_matchable(),
1077                        ])
1078                        .config(|this| {
1079                            this.optional();
1080                        })
1081                        .to_matchable(),
1082                    ])
1083                    .config(|this| {
1084                        this.optional();
1085                    })
1086                    .to_matchable(),
1087                    AnyNumberOf::new(vec![Ref::new("TableAttributeSegment").to_matchable()])
1088                        .config(|this| {
1089                            this.optional();
1090                        })
1091                        .to_matchable(),
1092                ])
1093                .to_matchable()
1094            })
1095            .to_matchable()
1096            .into(),
1097        ),
1098        (
1099            "CreateTableAsStatementSegment".into(),
1100            NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_| {
1101                Sequence::new(vec![
1102                    Ref::keyword("CREATE").to_matchable(),
1103                    Sequence::new(vec![
1104                        Ref::keyword("LOCAL").optional().to_matchable(),
1105                        one_of(vec![
1106                            Ref::keyword("TEMPORARY").to_matchable(),
1107                            Ref::keyword("TEMP").to_matchable(),
1108                        ])
1109                        .to_matchable(),
1110                    ])
1111                    .config(|this| {
1112                        this.optional();
1113                    })
1114                    .to_matchable(),
1115                    Ref::keyword("TABLE").to_matchable(),
1116                    Ref::new("ObjectReferenceSegment").to_matchable(),
1117                    Bracketed::new(vec![
1118                        Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
1119                            .to_matchable(),
1120                    ])
1121                    .config(|this| {
1122                        this.optional();
1123                    })
1124                    .to_matchable(),
1125                    Sequence::new(vec![
1126                        Ref::keyword("BACKUP").to_matchable(),
1127                        one_of(vec![
1128                            Ref::keyword("YES").to_matchable(),
1129                            Ref::keyword("NO").to_matchable(),
1130                        ])
1131                        .to_matchable(),
1132                    ])
1133                    .config(|this| {
1134                        this.optional();
1135                    })
1136                    .to_matchable(),
1137                    Ref::new("TableAttributeSegment").optional().to_matchable(),
1138                    Ref::keyword("AS").to_matchable(),
1139                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
1140                        .to_matchable(),
1141                ])
1142                .to_matchable()
1143            })
1144            .to_matchable()
1145            .into(),
1146        ),
1147        (
1148            "CreateModelStatementSegment".into(),
1149            NodeMatcher::new(SyntaxKind::CreateModelStatement, |_| {
1150                Sequence::new(vec![
1151                    Ref::keyword("CREATE").to_matchable(),
1152                    Ref::keyword("MODEL").to_matchable(),
1153                    Ref::new("ObjectReferenceSegment").to_matchable(),
1154                    Sequence::new(vec![
1155                        Ref::keyword("FROM").to_matchable(),
1156                        one_of(vec![
1157                            Ref::new("QuotedLiteralSegment").to_matchable(),
1158                            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
1159                                .to_matchable(),
1160                            Ref::new("ObjectReferenceSegment").to_matchable(),
1161                        ])
1162                        .to_matchable(),
1163                    ])
1164                    .config(|this| {
1165                        this.optional();
1166                    })
1167                    .to_matchable(),
1168                    Sequence::new(vec![
1169                        Ref::keyword("TARGET").to_matchable(),
1170                        Ref::new("ColumnReferenceSegment").to_matchable(),
1171                    ])
1172                    .config(|this| {
1173                        this.optional();
1174                    })
1175                    .to_matchable(),
1176                    Sequence::new(vec![
1177                        Ref::keyword("FUNCTION").to_matchable(),
1178                        Ref::new("ObjectReferenceSegment").to_matchable(),
1179                        Bracketed::new(vec![
1180                            Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()])
1181                                .to_matchable(),
1182                        ])
1183                        .config(|this| {
1184                            this.optional();
1185                        })
1186                        .to_matchable(),
1187                    ])
1188                    .to_matchable(),
1189                    Sequence::new(vec![
1190                        Ref::keyword("RETURNS").to_matchable(),
1191                        Ref::new("DatatypeSegment").to_matchable(),
1192                    ])
1193                    .config(|this| {
1194                        this.optional();
1195                    })
1196                    .to_matchable(),
1197                    Sequence::new(vec![
1198                        Ref::keyword("SAGEMAKER").to_matchable(),
1199                        Ref::new("QuotedLiteralSegment").to_matchable(),
1200                    ])
1201                    .config(|this| {
1202                        this.optional();
1203                    })
1204                    .to_matchable(),
1205                    Sequence::new(vec![
1206                        Ref::keyword("IAM_ROLE").to_matchable(),
1207                        one_of(vec![
1208                            Ref::keyword("DEFAULT").to_matchable(),
1209                            Ref::new("QuotedLiteralSegment").to_matchable(),
1210                        ])
1211                        .to_matchable(),
1212                    ])
1213                    .to_matchable(),
1214                    Sequence::new(vec![
1215                        Ref::keyword("AUTO").to_matchable(),
1216                        one_of(vec![
1217                            Ref::keyword("ON").to_matchable(),
1218                            Ref::keyword("OFF").to_matchable(),
1219                        ])
1220                        .to_matchable(),
1221                    ])
1222                    .config(|this| {
1223                        this.optional();
1224                    })
1225                    .to_matchable(),
1226                    Sequence::new(vec![
1227                        Ref::keyword("MODEL_TYPE").to_matchable(),
1228                        one_of(vec![
1229                            Ref::keyword("XGBOOST").to_matchable(),
1230                            Ref::keyword("MLP").to_matchable(),
1231                            Ref::keyword("KMEANS").to_matchable(),
1232                        ])
1233                        .to_matchable(),
1234                    ])
1235                    .config(|this| {
1236                        this.optional();
1237                    })
1238                    .to_matchable(),
1239                    Sequence::new(vec![
1240                        Ref::keyword("PROBLEM_TYPE").to_matchable(),
1241                        one_of(vec![
1242                            Ref::keyword("REGRESSION").to_matchable(),
1243                            Ref::keyword("BINARY_CLASSIFICATION").to_matchable(),
1244                            Ref::keyword("MULTICLASS_CLASSIFICATION").to_matchable(),
1245                        ])
1246                        .to_matchable(),
1247                    ])
1248                    .config(|this| {
1249                        this.optional();
1250                    })
1251                    .to_matchable(),
1252                    Sequence::new(vec![
1253                        Ref::keyword("OBJECTIVE").to_matchable(),
1254                        Ref::new("QuotedLiteralSegment").to_matchable(),
1255                    ])
1256                    .config(|this| {
1257                        this.optional();
1258                    })
1259                    .to_matchable(),
1260                    Sequence::new(vec![
1261                        Ref::keyword("PREPROCESSORS").to_matchable(),
1262                        Ref::new("QuotedLiteralSegment").to_matchable(),
1263                    ])
1264                    .config(|this| {
1265                        this.optional();
1266                    })
1267                    .to_matchable(),
1268                    Sequence::new(vec![
1269                        Ref::keyword("HYPERPARAMETERS").to_matchable(),
1270                        Ref::keyword("DEFAULT").to_matchable(),
1271                        Sequence::new(vec![
1272                            Ref::keyword("EXCEPT").to_matchable(),
1273                            Bracketed::new(vec![
1274                                Delimited::new(vec![Anything::new().to_matchable()]).to_matchable(),
1275                            ])
1276                            .to_matchable(),
1277                        ])
1278                        .config(|this| {
1279                            this.optional();
1280                        })
1281                        .to_matchable(),
1282                    ])
1283                    .config(|this| {
1284                        this.optional();
1285                    })
1286                    .to_matchable(),
1287                    Sequence::new(vec![
1288                        Ref::keyword("SETTINGS").to_matchable(),
1289                        Bracketed::new(vec![
1290                            Sequence::new(vec![
1291                                Ref::keyword("S3_BUCKET").to_matchable(),
1292                                Ref::new("QuotedLiteralSegment").to_matchable(),
1293                                Sequence::new(vec![
1294                                    Ref::keyword("KMS_KEY_ID").to_matchable(),
1295                                    Ref::new("QuotedLiteralSegment").to_matchable(),
1296                                ])
1297                                .config(|this| {
1298                                    this.optional();
1299                                })
1300                                .to_matchable(),
1301                                Sequence::new(vec![
1302                                    Ref::keyword("S3_GARBAGE_COLLECT").to_matchable(),
1303                                    one_of(vec![
1304                                        Ref::keyword("ON").to_matchable(),
1305                                        Ref::keyword("OFF").to_matchable(),
1306                                    ])
1307                                    .to_matchable(),
1308                                ])
1309                                .config(|this| {
1310                                    this.optional();
1311                                })
1312                                .to_matchable(),
1313                                Sequence::new(vec![
1314                                    Ref::keyword("MAX_CELLS").to_matchable(),
1315                                    Ref::new("NumericLiteralSegment").to_matchable(),
1316                                ])
1317                                .config(|this| {
1318                                    this.optional();
1319                                })
1320                                .to_matchable(),
1321                                Sequence::new(vec![
1322                                    Ref::keyword("MAX_RUNTIME").to_matchable(),
1323                                    Ref::new("NumericLiteralSegment").to_matchable(),
1324                                ])
1325                                .config(|this| {
1326                                    this.optional();
1327                                })
1328                                .to_matchable(),
1329                            ])
1330                            .to_matchable(),
1331                        ])
1332                        .to_matchable(),
1333                    ])
1334                    .config(|this| {
1335                        this.optional();
1336                    })
1337                    .to_matchable(),
1338                ])
1339                .to_matchable()
1340            })
1341            .to_matchable()
1342            .into(),
1343        ),
1344        (
1345            "ShowModelStatementSegment".into(),
1346            NodeMatcher::new(SyntaxKind::ShowModelStatement, |_| {
1347                Sequence::new(vec![
1348                    Ref::keyword("SHOW").to_matchable(),
1349                    Ref::keyword("MODEL").to_matchable(),
1350                    one_of(vec![
1351                        Ref::keyword("ALL").to_matchable(),
1352                        Ref::new("ObjectReferenceSegment").to_matchable(),
1353                    ])
1354                    .to_matchable(),
1355                ])
1356                .to_matchable()
1357            })
1358            .to_matchable()
1359            .into(),
1360        ),
1361        (
1362            "CreateExternalTableStatementSegment".into(),
1363            NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| {
1364                Sequence::new(vec![
1365                    Ref::keyword("CREATE").to_matchable(),
1366                    Ref::keyword("EXTERNAL").to_matchable(),
1367                    Ref::keyword("TABLE").to_matchable(),
1368                    Ref::new("TableReferenceSegment").to_matchable(),
1369                    Bracketed::new(vec![
1370                        Delimited::new(vec![
1371                            Sequence::new(vec![
1372                                Ref::new("ColumnReferenceSegment").to_matchable(),
1373                                Ref::new("DatatypeSegment").to_matchable(),
1374                            ])
1375                            .to_matchable(),
1376                        ])
1377                        .to_matchable(),
1378                    ])
1379                    .to_matchable(),
1380                    Ref::new("PartitionedBySegment").optional().to_matchable(),
1381                    Sequence::new(vec![
1382                        Ref::keyword("ROW").to_matchable(),
1383                        Ref::keyword("FORMAT").to_matchable(),
1384                        one_of(vec![
1385                            Sequence::new(vec![
1386                                Ref::keyword("DELIMITED").to_matchable(),
1387                                Ref::new("RowFormatDelimitedSegment").to_matchable(),
1388                            ])
1389                            .to_matchable(),
1390                            Sequence::new(vec![
1391                                Ref::keyword("SERDE").to_matchable(),
1392                                Ref::new("QuotedLiteralSegment").to_matchable(),
1393                                Sequence::new(vec![
1394                                    Ref::keyword("WITH").to_matchable(),
1395                                    Ref::keyword("SERDEPROPERTIES").to_matchable(),
1396                                    Bracketed::new(vec![
1397                                        Delimited::new(vec![
1398                                            Sequence::new(vec![
1399                                                Ref::new("QuotedLiteralSegment").to_matchable(),
1400                                                Ref::new("EqualsSegment").to_matchable(),
1401                                                Ref::new("QuotedLiteralSegment").to_matchable(),
1402                                            ])
1403                                            .to_matchable(),
1404                                        ])
1405                                        .to_matchable(),
1406                                    ])
1407                                    .to_matchable(),
1408                                ])
1409                                .config(|this| {
1410                                    this.optional();
1411                                })
1412                                .to_matchable(),
1413                            ])
1414                            .to_matchable(),
1415                        ])
1416                        .to_matchable(),
1417                    ])
1418                    .config(|this| {
1419                        this.optional();
1420                    })
1421                    .to_matchable(),
1422                    Ref::keyword("STORED").to_matchable(),
1423                    Ref::keyword("AS").to_matchable(),
1424                    one_of(vec![
1425                        Ref::keyword("PARQUET").to_matchable(),
1426                        Ref::keyword("RCFILE").to_matchable(),
1427                        Ref::keyword("SEQUENCEFILE").to_matchable(),
1428                        Ref::keyword("TEXTFILE").to_matchable(),
1429                        Ref::keyword("ORC").to_matchable(),
1430                        Ref::keyword("AVRO").to_matchable(),
1431                        Sequence::new(vec![
1432                            Ref::keyword("INPUTFORMAT").to_matchable(),
1433                            Ref::new("QuotedLiteralSegment").to_matchable(),
1434                            Ref::keyword("OUTPUTFORMAT").to_matchable(),
1435                            Ref::new("QuotedLiteralSegment").to_matchable(),
1436                        ])
1437                        .to_matchable(),
1438                    ])
1439                    .to_matchable(),
1440                    Ref::keyword("LOCATION").to_matchable(),
1441                    Ref::new("QuotedLiteralSegment").to_matchable(),
1442                    Sequence::new(vec![
1443                        Ref::keyword("TABLE").to_matchable(),
1444                        Ref::keyword("PROPERTIES").to_matchable(),
1445                        Bracketed::new(vec![
1446                            Delimited::new(vec![
1447                                Sequence::new(vec![
1448                                    Ref::new("QuotedLiteralSegment").to_matchable(),
1449                                    Ref::new("EqualsSegment").to_matchable(),
1450                                    Ref::new("QuotedLiteralSegment").to_matchable(),
1451                                ])
1452                                .to_matchable(),
1453                            ])
1454                            .to_matchable(),
1455                        ])
1456                        .to_matchable(),
1457                    ])
1458                    .config(|this| {
1459                        this.optional();
1460                    })
1461                    .to_matchable(),
1462                ])
1463                .to_matchable()
1464            })
1465            .to_matchable()
1466            .into(),
1467        ),
1468        (
1469            "CreateExternalTableAsStatementSegment".into(),
1470            NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| {
1471                Sequence::new(vec![
1472                    Ref::keyword("CREATE").to_matchable(),
1473                    Ref::keyword("EXTERNAL").to_matchable(),
1474                    Ref::keyword("TABLE").to_matchable(),
1475                    Ref::new("TableReferenceSegment").to_matchable(),
1476                    Ref::new("PartitionedBySegment").optional().to_matchable(),
1477                    Sequence::new(vec![
1478                        Ref::keyword("ROW").to_matchable(),
1479                        Ref::keyword("FORMAT").to_matchable(),
1480                        Ref::keyword("DELIMITED").to_matchable(),
1481                        Ref::new("RowFormatDelimitedSegment").to_matchable(),
1482                    ])
1483                    .config(|this| {
1484                        this.optional();
1485                    })
1486                    .to_matchable(),
1487                    Ref::keyword("STORED").to_matchable(),
1488                    Ref::keyword("AS").to_matchable(),
1489                    one_of(vec![
1490                        Ref::keyword("PARQUET").to_matchable(),
1491                        Ref::keyword("TEXTFILE").to_matchable(),
1492                    ])
1493                    .to_matchable(),
1494                    Ref::keyword("LOCATION").to_matchable(),
1495                    Ref::new("QuotedLiteralSegment").to_matchable(),
1496                    Sequence::new(vec![
1497                        Ref::keyword("TABLE").to_matchable(),
1498                        Ref::keyword("PROPERTIES").to_matchable(),
1499                        Bracketed::new(vec![
1500                            Delimited::new(vec![
1501                                Sequence::new(vec![
1502                                    Ref::new("QuotedLiteralSegment").to_matchable(),
1503                                    Ref::new("EqualsSegment").to_matchable(),
1504                                    Ref::new("QuotedLiteralSegment").to_matchable(),
1505                                ])
1506                                .to_matchable(),
1507                            ])
1508                            .to_matchable(),
1509                        ])
1510                        .to_matchable(),
1511                    ])
1512                    .config(|this| {
1513                        this.optional();
1514                    })
1515                    .to_matchable(),
1516                    Ref::keyword("AS").to_matchable(),
1517                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
1518                        .to_matchable(),
1519                ])
1520                .to_matchable()
1521            })
1522            .to_matchable()
1523            .into(),
1524        ),
1525        (
1526            "CreateExternalSchemaStatementSegment".into(),
1527            NodeMatcher::new(SyntaxKind::CreateExternalSchemaStatement, |_| {
1528                Sequence::new(vec![
1529                    Ref::keyword("CREATE").to_matchable(),
1530                    Ref::keyword("EXTERNAL").to_matchable(),
1531                    Ref::keyword("SCHEMA").to_matchable(),
1532                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1533                    Ref::new("SchemaReferenceSegment").to_matchable(),
1534                    Ref::keyword("FROM").to_matchable(),
1535                    one_of(vec![
1536                        Sequence::new(vec![
1537                            Ref::keyword("DATA").to_matchable(),
1538                            Ref::keyword("CATALOG").to_matchable(),
1539                        ])
1540                        .to_matchable(),
1541                        Sequence::new(vec![
1542                            Ref::keyword("HIVE").to_matchable(),
1543                            Ref::keyword("METASTORE").to_matchable(),
1544                        ])
1545                        .to_matchable(),
1546                        Ref::keyword("POSTGRES").to_matchable(),
1547                        Ref::keyword("MYSQL").to_matchable(),
1548                        Ref::keyword("KINESIS").to_matchable(),
1549                        Ref::keyword("REDSHIFT").to_matchable(),
1550                    ])
1551                    .to_matchable(),
1552                    any_set_of(vec![
1553                        Sequence::new(vec![
1554                            Ref::keyword("DATABASE").to_matchable(),
1555                            Ref::new("QuotedLiteralSegment").to_matchable(),
1556                        ])
1557                        .to_matchable(),
1558                        Sequence::new(vec![
1559                            Ref::keyword("REGION").to_matchable(),
1560                            Ref::new("QuotedLiteralSegment").to_matchable(),
1561                        ])
1562                        .to_matchable(),
1563                        Sequence::new(vec![
1564                            Ref::keyword("SCHEMA").to_matchable(),
1565                            Ref::new("QuotedLiteralSegment").to_matchable(),
1566                        ])
1567                        .to_matchable(),
1568                        Sequence::new(vec![
1569                            Ref::keyword("URI").to_matchable(),
1570                            Ref::new("QuotedLiteralSegment").to_matchable(),
1571                            Sequence::new(vec![
1572                                Ref::keyword("PORT").to_matchable(),
1573                                Ref::new("NumericLiteralSegment").to_matchable(),
1574                            ])
1575                            .config(|this| {
1576                                this.optional();
1577                            })
1578                            .to_matchable(),
1579                        ])
1580                        .to_matchable(),
1581                        Sequence::new(vec![
1582                            Ref::keyword("IAM_ROLE").to_matchable(),
1583                            one_of(vec![
1584                                Ref::keyword("DEFAULT").to_matchable(),
1585                                Ref::new("QuotedLiteralSegment").to_matchable(),
1586                            ])
1587                            .to_matchable(),
1588                        ])
1589                        .to_matchable(),
1590                        Sequence::new(vec![
1591                            Ref::keyword("SECRET_ARN").to_matchable(),
1592                            Ref::new("QuotedLiteralSegment").to_matchable(),
1593                        ])
1594                        .to_matchable(),
1595                        Sequence::new(vec![
1596                            Ref::keyword("CATALOG_ROLE").to_matchable(),
1597                            Ref::new("QuotedLiteralSegment").to_matchable(),
1598                        ])
1599                        .to_matchable(),
1600                        Sequence::new(vec![
1601                            Ref::keyword("CREATE").to_matchable(),
1602                            Ref::keyword("EXTERNAL").to_matchable(),
1603                            Ref::keyword("DATABASE").to_matchable(),
1604                            Ref::keyword("IF").to_matchable(),
1605                            Ref::keyword("NOT").to_matchable(),
1606                            Ref::keyword("EXISTS").to_matchable(),
1607                        ])
1608                        .to_matchable(),
1609                    ])
1610                    .config(|this| {
1611                        this.optional();
1612                    })
1613                    .to_matchable(),
1614                ])
1615                .to_matchable()
1616            })
1617            .to_matchable()
1618            .into(),
1619        ),
1620        (
1621            "CreateLibraryStatementSegment".into(),
1622            NodeMatcher::new(SyntaxKind::CreateLibraryStatement, |_| {
1623                Sequence::new(vec![
1624                    Ref::keyword("CREATE").to_matchable(),
1625                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
1626                    Ref::keyword("LIBRARY").to_matchable(),
1627                    Ref::new("ObjectReferenceSegment").to_matchable(),
1628                    Ref::keyword("LANGUAGE").to_matchable(),
1629                    Ref::keyword("PLPYTHONU").to_matchable(),
1630                    Ref::keyword("FROM").to_matchable(),
1631                    Ref::new("QuotedLiteralSegment").to_matchable(),
1632                    any_set_of(vec![
1633                        Ref::new("AuthorizationSegment").to_matchable(),
1634                        Sequence::new(vec![
1635                            Ref::keyword("REGION").to_matchable(),
1636                            Ref::keyword("AS").optional().to_matchable(),
1637                            Ref::new("QuotedLiteralSegment").to_matchable(),
1638                        ])
1639                        .config(|this| {
1640                            this.optional();
1641                        })
1642                        .to_matchable(),
1643                    ])
1644                    .to_matchable(),
1645                ])
1646                .to_matchable()
1647            })
1648            .to_matchable()
1649            .into(),
1650        ),
1651        (
1652            "UnloadStatementSegment".into(),
1653            NodeMatcher::new(SyntaxKind::UnloadStatement, |_| {
1654                Sequence::new(vec![
1655                    Ref::keyword("UNLOAD").to_matchable(),
1656                    Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()])
1657                        .to_matchable(),
1658                    Ref::keyword("TO").to_matchable(),
1659                    Ref::new("QuotedLiteralSegment").to_matchable(),
1660                    any_set_of(vec![
1661                        Ref::new("AuthorizationSegment").to_matchable(),
1662                        Sequence::new(vec![
1663                            Ref::keyword("REGION").to_matchable(),
1664                            Ref::keyword("AS").optional().to_matchable(),
1665                            Ref::new("QuotedLiteralSegment").to_matchable(),
1666                        ])
1667                        .config(|this| {
1668                            this.optional();
1669                        })
1670                        .to_matchable(),
1671                        Ref::new("CompressionTypeGrammar").optional().to_matchable(),
1672                        Sequence::new(vec![
1673                            Sequence::new(vec![
1674                                Ref::keyword("FORMAT").to_matchable(),
1675                                Ref::keyword("AS").optional().to_matchable(),
1676                            ])
1677                            .config(|this| {
1678                                this.optional();
1679                            })
1680                            .to_matchable(),
1681                            one_of(vec![
1682                                Ref::keyword("CSV").to_matchable(),
1683                                Ref::keyword("JSON").to_matchable(),
1684                                Ref::keyword("PARQUET").to_matchable(),
1685                            ])
1686                            .to_matchable(),
1687                        ])
1688                        .config(|this| {
1689                            this.optional();
1690                        })
1691                        .to_matchable(),
1692                        Sequence::new(vec![
1693                            Ref::keyword("PARTITION").to_matchable(),
1694                            Ref::keyword("BY").to_matchable(),
1695                            Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
1696                            Ref::keyword("INCLUDE").optional().to_matchable(),
1697                        ])
1698                        .to_matchable(),
1699                        Sequence::new(vec![
1700                            Ref::keyword("PARALLEL").to_matchable(),
1701                            one_of(vec![
1702                                Ref::keyword("PRESET").to_matchable(),
1703                                Ref::keyword("ON").to_matchable(),
1704                                Ref::keyword("OFF").to_matchable(),
1705                                Ref::keyword("TRUE").to_matchable(),
1706                                Ref::keyword("FALSE").to_matchable(),
1707                            ])
1708                            .config(|this| {
1709                                this.optional();
1710                            })
1711                            .to_matchable(),
1712                        ])
1713                        .config(|this| {
1714                            this.optional();
1715                        })
1716                        .to_matchable(),
1717                        one_of(vec![
1718                            Sequence::new(vec![
1719                                Ref::keyword("DELIMITER").to_matchable(),
1720                                Ref::keyword("AS").optional().to_matchable(),
1721                                Ref::new("QuotedLiteralSegment").to_matchable(),
1722                            ])
1723                            .to_matchable(),
1724                            Sequence::new(vec![
1725                                Ref::keyword("FIXEDWIDTH").to_matchable(),
1726                                Ref::keyword("AS").optional().to_matchable(),
1727                                Ref::new("QuotedLiteralSegment").to_matchable(),
1728                            ])
1729                            .to_matchable(),
1730                        ])
1731                        .config(|this| {
1732                            this.optional();
1733                        })
1734                        .to_matchable(),
1735                        Sequence::new(vec![
1736                            Ref::keyword("MANIFEST").to_matchable(),
1737                            Ref::keyword("VERBOSE").optional().to_matchable(),
1738                        ])
1739                        .config(|this| {
1740                            this.optional();
1741                        })
1742                        .to_matchable(),
1743                        Sequence::new(vec![
1744                            Ref::keyword("NULL").to_matchable(),
1745                            Ref::keyword("AS").to_matchable(),
1746                            Ref::new("QuotedLiteralSegment").to_matchable(),
1747                        ])
1748                        .config(|this| {
1749                            this.optional();
1750                        })
1751                        .to_matchable(),
1752                        Sequence::new(vec![
1753                            Ref::keyword("NULL").to_matchable(),
1754                            Ref::keyword("AS").to_matchable(),
1755                            Ref::new("QuotedLiteralSegment").to_matchable(),
1756                        ])
1757                        .config(|this| {
1758                            this.optional();
1759                        })
1760                        .to_matchable(),
1761                        any_set_of(vec![
1762                            one_of(vec![
1763                                Ref::keyword("MAXFILESIZE").to_matchable(),
1764                                Ref::keyword("ROWGROUPSIZE").to_matchable(),
1765                            ])
1766                            .to_matchable(),
1767                            Ref::keyword("AS").optional().to_matchable(),
1768                            Ref::new("NumericLiteralSegment").to_matchable(),
1769                            one_of(vec![
1770                                Ref::keyword("MB").to_matchable(),
1771                                Ref::keyword("GB").to_matchable(),
1772                            ])
1773                            .to_matchable(),
1774                        ])
1775                        .config(|this| {
1776                            this.optional();
1777                        })
1778                        .to_matchable(),
1779                        Sequence::new(vec![
1780                            Ref::keyword("ENCRYPTED").to_matchable(),
1781                            Ref::keyword("AUTO").optional().to_matchable(),
1782                        ])
1783                        .config(|this| {
1784                            this.optional();
1785                        })
1786                        .to_matchable(),
1787                        Ref::keyword("ALLOWOVERWRITE").optional().to_matchable(),
1788                        Ref::keyword("CLEANPATH").optional().to_matchable(),
1789                        Ref::keyword("ESCAPE").optional().to_matchable(),
1790                        Ref::keyword("ADDQUOTES").optional().to_matchable(),
1791                        Ref::keyword("HEADER").optional().to_matchable(),
1792                    ])
1793                    .to_matchable(),
1794                ])
1795                .to_matchable()
1796            })
1797            .to_matchable()
1798            .into(),
1799        ),
1800    ]);
1801    redshift_dialect.replace_grammar(
1802        "CopyStatementSegment",
1803        Sequence::new(vec![
1804            Ref::keyword("COPY").to_matchable(),
1805            Ref::new("TableReferenceSegment").to_matchable(),
1806            Ref::new("BracketedColumnReferenceListGrammar")
1807                .optional()
1808                .to_matchable(),
1809            Ref::keyword("FROM").to_matchable(),
1810            Ref::new("QuotedLiteralSegment").to_matchable(),
1811            any_set_of(vec![
1812                Ref::new("AuthorizationSegment").to_matchable(),
1813                Sequence::new(vec![
1814                    Ref::keyword("REGION").to_matchable(),
1815                    Ref::keyword("AS").optional().to_matchable(),
1816                    Ref::new("QuotedLiteralSegment").to_matchable(),
1817                ])
1818                .config(|this| {
1819                    this.optional();
1820                })
1821                .to_matchable(),
1822                Ref::new("CompressionTypeGrammar").optional().to_matchable(),
1823                Ref::new("DataFormatSegment").optional().to_matchable(),
1824                one_of(vec![
1825                    Sequence::new(vec![
1826                        Ref::keyword("DELIMITER").to_matchable(),
1827                        Ref::keyword("AS").optional().to_matchable(),
1828                        Ref::new("QuotedLiteralSegment").to_matchable(),
1829                    ])
1830                    .to_matchable(),
1831                    Sequence::new(vec![
1832                        Ref::keyword("FIXEDWIDTH").to_matchable(),
1833                        Ref::keyword("AS").optional().to_matchable(),
1834                        Ref::new("QuotedLiteralSegment").to_matchable(),
1835                    ])
1836                    .to_matchable(),
1837                ])
1838                .config(|this| {
1839                    this.optional();
1840                })
1841                .to_matchable(),
1842                Sequence::new(vec![
1843                    Ref::keyword("ENCRYPTED").to_matchable(),
1844                    Ref::keyword("AUTO").optional().to_matchable(),
1845                ])
1846                .config(|this| {
1847                    this.optional();
1848                })
1849                .to_matchable(),
1850                Ref::keyword("MANIFEST").optional().to_matchable(),
1851                Sequence::new(vec![
1852                    Ref::keyword("COMPROWS").to_matchable(),
1853                    Ref::new("NumericLiteralSegment").to_matchable(),
1854                ])
1855                .config(|this| {
1856                    this.optional();
1857                })
1858                .to_matchable(),
1859                Sequence::new(vec![
1860                    Ref::keyword("MAXERROR").to_matchable(),
1861                    Ref::keyword("AS").optional().to_matchable(),
1862                    Ref::new("NumericLiteralSegment").to_matchable(),
1863                ])
1864                .config(|this| {
1865                    this.optional();
1866                })
1867                .to_matchable(),
1868                Sequence::new(vec![
1869                    Ref::keyword("COMPUPDATE").to_matchable(),
1870                    one_of(vec![
1871                        Ref::keyword("PRESET").to_matchable(),
1872                        Ref::keyword("ON").to_matchable(),
1873                        Ref::keyword("OFF").to_matchable(),
1874                        Ref::keyword("TRUE").to_matchable(),
1875                        Ref::keyword("FALSE").to_matchable(),
1876                    ])
1877                    .config(|this| {
1878                        this.optional();
1879                    })
1880                    .to_matchable(),
1881                ])
1882                .config(|this| {
1883                    this.optional();
1884                })
1885                .to_matchable(),
1886                Sequence::new(vec![
1887                    Ref::keyword("STATUPDATE").to_matchable(),
1888                    one_of(vec![
1889                        Ref::keyword("ON").to_matchable(),
1890                        Ref::keyword("OFF").to_matchable(),
1891                        Ref::keyword("TRUE").to_matchable(),
1892                        Ref::keyword("FALSE").to_matchable(),
1893                    ])
1894                    .config(|this| {
1895                        this.optional();
1896                    })
1897                    .to_matchable(),
1898                ])
1899                .config(|this| {
1900                    this.optional();
1901                })
1902                .to_matchable(),
1903                Ref::keyword("NOLOAD").optional().to_matchable(),
1904                Ref::keyword("ACCEPTANYDATE").optional().to_matchable(),
1905                Sequence::new(vec![
1906                    Ref::keyword("ACCEPTINVCHARS").to_matchable(),
1907                    Ref::keyword("AS").optional().to_matchable(),
1908                    Ref::new("QuotedLiteralSegment").optional().to_matchable(),
1909                ])
1910                .config(|this| {
1911                    this.optional();
1912                })
1913                .to_matchable(),
1914                Ref::keyword("BLANKSASNULL").optional().to_matchable(),
1915                Sequence::new(vec![
1916                    Ref::keyword("DATEFORMAT").to_matchable(),
1917                    Ref::keyword("AS").optional().to_matchable(),
1918                    one_of(vec![
1919                        Ref::keyword("AUTO").to_matchable(),
1920                        Ref::new("QuotedLiteralSegment").to_matchable(),
1921                    ])
1922                    .to_matchable(),
1923                ])
1924                .config(|this| {
1925                    this.optional();
1926                })
1927                .to_matchable(),
1928                Ref::keyword("EMPTYASNULL").optional().to_matchable(),
1929                Sequence::new(vec![
1930                    Ref::keyword("ENCODING").to_matchable(),
1931                    Ref::keyword("AS").optional().to_matchable(),
1932                    one_of(vec![
1933                        Ref::keyword("UTF8").to_matchable(),
1934                        Ref::keyword("UTF16").to_matchable(),
1935                        Ref::keyword("UTF16BE").to_matchable(),
1936                        Ref::keyword("UTF16LE").to_matchable(),
1937                    ])
1938                    .to_matchable(),
1939                ])
1940                .config(|this| {
1941                    this.optional();
1942                })
1943                .to_matchable(),
1944                Ref::keyword("ESCAPE").optional().to_matchable(),
1945                Ref::keyword("EXPLICIT_IDS").optional().to_matchable(),
1946                Ref::keyword("FILLRECORD").optional().to_matchable(),
1947                Ref::keyword("IGNOREBLANKLINES").optional().to_matchable(),
1948                Sequence::new(vec![
1949                    Ref::keyword("IGNOREHEADER").to_matchable(),
1950                    Ref::keyword("AS").optional().to_matchable(),
1951                    Ref::new("LiteralGrammar").to_matchable(),
1952                ])
1953                .config(|this| {
1954                    this.optional();
1955                })
1956                .to_matchable(),
1957                Sequence::new(vec![
1958                    Ref::keyword("NULL").to_matchable(),
1959                    Ref::keyword("AS").to_matchable(),
1960                    Ref::new("QuotedLiteralSegment").to_matchable(),
1961                ])
1962                .config(|this| {
1963                    this.optional();
1964                })
1965                .to_matchable(),
1966                Sequence::new(vec![
1967                    Ref::keyword("READRATIO").to_matchable(),
1968                    Ref::new("NumericLiteralSegment").to_matchable(),
1969                ])
1970                .config(|this| {
1971                    this.optional();
1972                })
1973                .to_matchable(),
1974                Ref::keyword("REMOVEQUOTES").optional().to_matchable(),
1975                Ref::keyword("ROUNDEC").optional().to_matchable(),
1976                Sequence::new(vec![
1977                    Ref::keyword("TIMEFORMAT").to_matchable(),
1978                    Ref::keyword("AS").optional().to_matchable(),
1979                    one_of(vec![
1980                        Ref::keyword("AUTO").to_matchable(),
1981                        Ref::keyword("EPOCHSECS").to_matchable(),
1982                        Ref::keyword("EPOCHMILLISECS").to_matchable(),
1983                        Ref::new("QuotedLiteralSegment").to_matchable(),
1984                    ])
1985                    .to_matchable(),
1986                ])
1987                .config(|this| {
1988                    this.optional();
1989                })
1990                .to_matchable(),
1991                Ref::keyword("TRIMBLANKS").optional().to_matchable(),
1992                Ref::keyword("TRUNCATECOLUMNS").optional().to_matchable(),
1993            ])
1994            .to_matchable(),
1995        ])
1996        .to_matchable(),
1997    );
1998    redshift_dialect.add([
1999        (
2000            "InsertStatementSegment".into(),
2001            NodeMatcher::new(SyntaxKind::InsertStatement, |_| {
2002                Sequence::new(vec![
2003                    Ref::keyword("INSERT").to_matchable(),
2004                    Ref::keyword("INTO").to_matchable(),
2005                    Ref::new("TableReferenceSegment").to_matchable(),
2006                    one_of(vec![
2007                        optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
2008                            .to_matchable(),
2009                        Sequence::new(vec![
2010                            Ref::keyword("DEFAULT").to_matchable(),
2011                            Ref::keyword("VALUES").to_matchable(),
2012                        ])
2013                        .to_matchable(),
2014                        Sequence::new(vec![
2015                            Ref::new("BracketedColumnReferenceListGrammar")
2016                                .optional()
2017                                .to_matchable(),
2018                            one_of(vec![
2019                                Ref::new("ValuesClauseSegment").to_matchable(),
2020                                optionally_bracketed(vec![
2021                                    Ref::new("SelectableGrammar").to_matchable(),
2022                                ])
2023                                .to_matchable(),
2024                            ])
2025                            .to_matchable(),
2026                        ])
2027                        .to_matchable(),
2028                    ])
2029                    .to_matchable(),
2030                ])
2031                .to_matchable()
2032            })
2033            .to_matchable()
2034            .into(),
2035        ),
2036        (
2037            "CreateSchemaStatementSegment".into(),
2038            NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_| {
2039                Sequence::new(vec![
2040                    Ref::keyword("CREATE").to_matchable(),
2041                    Ref::keyword("SCHEMA").to_matchable(),
2042                    one_of(vec![
2043                        Sequence::new(vec![
2044                            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2045                            Ref::new("SchemaReferenceSegment").to_matchable(),
2046                            Sequence::new(vec![
2047                                Ref::keyword("AUTHORIZATION").to_matchable(),
2048                                Ref::new("RoleReferenceSegment").to_matchable(),
2049                            ])
2050                            .config(|this| {
2051                                this.optional();
2052                            })
2053                            .to_matchable(),
2054                        ])
2055                        .to_matchable(),
2056                        Sequence::new(vec![
2057                            Ref::keyword("AUTHORIZATION").to_matchable(),
2058                            Ref::new("RoleReferenceSegment").to_matchable(),
2059                        ])
2060                        .to_matchable(),
2061                    ])
2062                    .to_matchable(),
2063                    Ref::new("QuotaGrammar").optional().to_matchable(),
2064                ])
2065                .to_matchable()
2066            })
2067            .to_matchable()
2068            .into(),
2069        ),
2070        (
2071            "ProcedureParameterListSegment".into(),
2072            NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_| {
2073                let param_type = one_of(vec![
2074                    Ref::keyword("REFCURSOR").to_matchable(),
2075                    Ref::new("DatatypeSegment").to_matchable(),
2076                ]);
2077                Bracketed::new(vec![
2078                    Delimited::new(vec![
2079                        Sequence::new(vec![
2080                            AnyNumberOf::new(vec![
2081                                Ref::new("ParameterNameSegment")
2082                                    .exclude(one_of(vec![
2083                                        param_type.clone().to_matchable(),
2084                                        Ref::new("ArgModeGrammar").to_matchable(),
2085                                    ]))
2086                                    .optional()
2087                                    .to_matchable(),
2088                                Ref::new("ArgModeGrammar").optional().to_matchable(),
2089                            ])
2090                            .config(|this| {
2091                                this.max_times_per_element = 1.into();
2092                            })
2093                            .to_matchable(),
2094                            param_type.clone().to_matchable(),
2095                        ])
2096                        .to_matchable(),
2097                    ])
2098                    .config(|this| {
2099                        this.optional();
2100                    })
2101                    .to_matchable(),
2102                ])
2103                .to_matchable()
2104            })
2105            .to_matchable()
2106            .into(),
2107        ),
2108        (
2109            "CreateProcedureStatementSegment".into(),
2110            NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| {
2111                Sequence::new(vec![
2112                    Ref::keyword("CREATE").to_matchable(),
2113                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
2114                    Ref::keyword("PROCEDURE").to_matchable(),
2115                    Ref::new("FunctionNameSegment").to_matchable(),
2116                    Ref::new("ProcedureParameterListSegment").to_matchable(),
2117                    Ref::new("FunctionDefinitionGrammar").to_matchable(),
2118                ])
2119                .to_matchable()
2120            })
2121            .to_matchable()
2122            .into(),
2123        ),
2124        (
2125            "AlterProcedureStatementSegment".into(),
2126            NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_| {
2127                Sequence::new(vec![
2128                    Ref::keyword("ALTER").to_matchable(),
2129                    Ref::keyword("PROCEDURE").to_matchable(),
2130                    Ref::new("FunctionNameSegment").to_matchable(),
2131                    Ref::new("ProcedureParameterListSegment")
2132                        .optional()
2133                        .to_matchable(),
2134                    one_of(vec![
2135                        Sequence::new(vec![
2136                            Ref::keyword("RENAME").to_matchable(),
2137                            Ref::keyword("TO").to_matchable(),
2138                            Ref::new("FunctionNameSegment").to_matchable(),
2139                        ])
2140                        .to_matchable(),
2141                        Sequence::new(vec![
2142                            Ref::keyword("OWNER").to_matchable(),
2143                            Ref::keyword("TO").to_matchable(),
2144                            one_of(vec![
2145                                one_of(vec![
2146                                    Ref::new("ParameterNameSegment").to_matchable(),
2147                                    Ref::new("QuotedIdentifierSegment").to_matchable(),
2148                                ])
2149                                .to_matchable(),
2150                                Ref::keyword("CURRENT_USER").to_matchable(),
2151                                Ref::keyword("SESSION_USER").to_matchable(),
2152                            ])
2153                            .to_matchable(),
2154                        ])
2155                        .to_matchable(),
2156                    ])
2157                    .to_matchable(),
2158                ])
2159                .to_matchable()
2160            })
2161            .to_matchable()
2162            .into(),
2163        ),
2164        (
2165            "DropProcedureStatementSegment".into(),
2166            NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_| {
2167                Sequence::new(vec![
2168                    Ref::keyword("DROP").to_matchable(),
2169                    Ref::keyword("PROCEDURE").to_matchable(),
2170                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2171                    Delimited::new(vec![
2172                        Sequence::new(vec![
2173                            Ref::new("FunctionNameSegment").to_matchable(),
2174                            Ref::new("ProcedureParameterListSegment")
2175                                .optional()
2176                                .to_matchable(),
2177                        ])
2178                        .to_matchable(),
2179                    ])
2180                    .to_matchable(),
2181                ])
2182                .to_matchable()
2183            })
2184            .to_matchable()
2185            .into(),
2186        ),
2187    ]);
2188
2189    redshift_dialect.replace_grammar(
2190        "AlterDefaultPrivilegesSchemaObjectsSegment",
2191        postgres_dialect
2192            .grammar("AlterDefaultPrivilegesSchemaObjectsSegment")
2193            .match_grammar(&postgres_dialect)
2194            .unwrap()
2195            .copy(
2196                Some(vec![
2197                    Sequence::new(vec![Ref::keyword("PROCEDURES").to_matchable()]).to_matchable(),
2198                ]),
2199                None,
2200                None,
2201                None,
2202                Vec::new(),
2203                false,
2204            ),
2205    );
2206
2207    redshift_dialect.add([
2208        (
2209            "DeclareStatementSegment".into(),
2210            NodeMatcher::new(SyntaxKind::DeclareStatement, |_| {
2211                Sequence::new(vec![
2212                    Ref::keyword("DECLARE").to_matchable(),
2213                    Ref::new("ObjectReferenceSegment").to_matchable(),
2214                    Ref::keyword("CURSOR").to_matchable(),
2215                    Ref::keyword("FOR").to_matchable(),
2216                    Ref::new("SelectableGrammar").to_matchable(),
2217                ])
2218                .to_matchable()
2219            })
2220            .to_matchable()
2221            .into(),
2222        ),
2223        (
2224            "FetchStatementSegment".into(),
2225            NodeMatcher::new(SyntaxKind::FetchStatement, |_| {
2226                Sequence::new(vec![
2227                    Ref::keyword("FETCH").to_matchable(),
2228                    one_of(vec![
2229                        Ref::keyword("NEXT").to_matchable(),
2230                        Ref::keyword("ALL").to_matchable(),
2231                        Sequence::new(vec![
2232                            Ref::keyword("FORWARD").to_matchable(),
2233                            one_of(vec![
2234                                Ref::keyword("ALL").to_matchable(),
2235                                Ref::new("NumericLiteralSegment").to_matchable(),
2236                            ])
2237                            .to_matchable(),
2238                        ])
2239                        .to_matchable(),
2240                    ])
2241                    .to_matchable(),
2242                    Ref::keyword("FROM").to_matchable(),
2243                    Ref::new("ObjectReferenceSegment").to_matchable(),
2244                ])
2245                .to_matchable()
2246            })
2247            .to_matchable()
2248            .into(),
2249        ),
2250        (
2251            "CloseStatementSegment".into(),
2252            NodeMatcher::new(SyntaxKind::CloseStatement, |_| {
2253                Sequence::new(vec![
2254                    Ref::keyword("CLOSE").to_matchable(),
2255                    Ref::new("ObjectReferenceSegment").to_matchable(),
2256                ])
2257                .to_matchable()
2258            })
2259            .to_matchable()
2260            .into(),
2261        ),
2262        (
2263            "AltereDatashareStatementSegment".into(),
2264            NodeMatcher::new(SyntaxKind::CreateDatashareStatement, |_| {
2265                Sequence::new(vec![
2266                    Ref::keyword("ALTER").to_matchable(),
2267                    Ref::keyword("DATASHARE").to_matchable(),
2268                    Ref::new("ObjectReferenceSegment").to_matchable(),
2269                    one_of(vec![
2270                        Sequence::new(vec![
2271                            one_of(vec![
2272                                Ref::keyword("ADD").to_matchable(),
2273                                Ref::keyword("REMOVE").to_matchable(),
2274                            ])
2275                            .to_matchable(),
2276                            one_of(vec![
2277                                Sequence::new(vec![
2278                                    Ref::keyword("TABLE").to_matchable(),
2279                                    Delimited::new(vec![
2280                                        Ref::new("TableReferenceSegment").to_matchable(),
2281                                    ])
2282                                    .to_matchable(),
2283                                ])
2284                                .to_matchable(),
2285                                Sequence::new(vec![
2286                                    Ref::keyword("SCHEMA").to_matchable(),
2287                                    Delimited::new(vec![
2288                                        Ref::new("SchemaReferenceSegment").to_matchable(),
2289                                    ])
2290                                    .to_matchable(),
2291                                ])
2292                                .to_matchable(),
2293                                Sequence::new(vec![
2294                                    Ref::keyword("FUNCTION").to_matchable(),
2295                                    Delimited::new(vec![
2296                                        Ref::new("FunctionNameSegment").to_matchable(),
2297                                    ])
2298                                    .to_matchable(),
2299                                ])
2300                                .to_matchable(),
2301                                Sequence::new(vec![
2302                                    Ref::keyword("ALL").to_matchable(),
2303                                    one_of(vec![
2304                                        Ref::keyword("TABLES").to_matchable(),
2305                                        Ref::keyword("FUNCTIONS").to_matchable(),
2306                                    ])
2307                                    .to_matchable(),
2308                                    Ref::keyword("IN").to_matchable(),
2309                                    Ref::keyword("SCHEMA").to_matchable(),
2310                                    Delimited::new(vec![
2311                                        Ref::new("SchemaReferenceSegment").to_matchable(),
2312                                    ])
2313                                    .to_matchable(),
2314                                ])
2315                                .to_matchable(),
2316                            ])
2317                            .to_matchable(),
2318                        ])
2319                        .to_matchable(),
2320                        Sequence::new(vec![
2321                            Ref::keyword("SET").to_matchable(),
2322                            one_of(vec![
2323                                Sequence::new(vec![
2324                                    Ref::keyword("PUBLICACCESSIBLE").to_matchable(),
2325                                    Ref::new("EqualsSegment").optional().to_matchable(),
2326                                    Ref::new("BooleanLiteralGrammar").to_matchable(),
2327                                ])
2328                                .to_matchable(),
2329                                Sequence::new(vec![
2330                                    Ref::keyword("INCLUDENEW").to_matchable(),
2331                                    Ref::new("EqualsSegment").optional().to_matchable(),
2332                                    Ref::new("BooleanLiteralGrammar").to_matchable(),
2333                                    Ref::keyword("FOR").to_matchable(),
2334                                    Ref::keyword("SCHEMA").to_matchable(),
2335                                    Ref::new("SchemaReferenceSegment").to_matchable(),
2336                                ])
2337                                .to_matchable(),
2338                            ])
2339                            .to_matchable(),
2340                        ])
2341                        .to_matchable(),
2342                    ])
2343                    .to_matchable(),
2344                ])
2345                .to_matchable()
2346            })
2347            .to_matchable()
2348            .into(),
2349        ),
2350        (
2351            "CreateDatashareStatementSegment".into(),
2352            NodeMatcher::new(SyntaxKind::CreateDatashareStatement, |_| {
2353                Sequence::new(vec![
2354                    Ref::keyword("CREATE").to_matchable(),
2355                    Ref::keyword("DATASHARE").to_matchable(),
2356                    Ref::new("ObjectReferenceSegment").to_matchable(),
2357                    Sequence::new(vec![
2358                        Ref::keyword("SET").optional().to_matchable(),
2359                        Ref::keyword("PUBLICACCESSIBLE").to_matchable(),
2360                        Ref::new("EqualsSegment").optional().to_matchable(),
2361                        one_of(vec![
2362                            Ref::keyword("TRUE").to_matchable(),
2363                            Ref::keyword("FALSE").to_matchable(),
2364                        ])
2365                        .to_matchable(),
2366                    ])
2367                    .config(|this| {
2368                        this.optional();
2369                    })
2370                    .to_matchable(),
2371                ])
2372                .to_matchable()
2373            })
2374            .to_matchable()
2375            .into(),
2376        ),
2377        (
2378            "DescDatashareStatementSegment".into(),
2379            NodeMatcher::new(SyntaxKind::DescDatashareStatement, |_| {
2380                Sequence::new(vec![
2381                    Ref::keyword("DESC").to_matchable(),
2382                    Ref::keyword("DATASHARE").to_matchable(),
2383                    Ref::new("ObjectReferenceSegment").to_matchable(),
2384                    Sequence::new(vec![
2385                        Ref::keyword("OF").to_matchable(),
2386                        Sequence::new(vec![
2387                            Ref::keyword("ACCOUNT").to_matchable(),
2388                            Ref::new("QuotedLiteralSegment").to_matchable(),
2389                        ])
2390                        .config(|this| {
2391                            this.optional();
2392                        })
2393                        .to_matchable(),
2394                        Ref::keyword("NAMESPACE").to_matchable(),
2395                        Ref::new("QuotedLiteralSegment").to_matchable(),
2396                    ])
2397                    .config(|this| {
2398                        this.optional();
2399                    })
2400                    .to_matchable(),
2401                ])
2402                .to_matchable()
2403            })
2404            .to_matchable()
2405            .into(),
2406        ),
2407        (
2408            "DropDatashareStatementSegment".into(),
2409            NodeMatcher::new(SyntaxKind::DropDatashareStatement, |_| {
2410                Sequence::new(vec![
2411                    Ref::keyword("DROP").to_matchable(),
2412                    Ref::keyword("DATASHARE").to_matchable(),
2413                    Ref::new("ObjectReferenceSegment").to_matchable(),
2414                ])
2415                .to_matchable()
2416            })
2417            .to_matchable()
2418            .into(),
2419        ),
2420        (
2421            "ShowDatasharesStatementSegment".into(),
2422            NodeMatcher::new(SyntaxKind::ShowDatasharesStatement, |_| {
2423                Sequence::new(vec![
2424                    Ref::keyword("SHOW").to_matchable(),
2425                    Ref::keyword("DATASHARES").to_matchable(),
2426                    Sequence::new(vec![
2427                        Ref::keyword("LIKE").to_matchable(),
2428                        Ref::new("QuotedLiteralSegment").to_matchable(),
2429                    ])
2430                    .config(|this| {
2431                        this.optional();
2432                    })
2433                    .to_matchable(),
2434                ])
2435                .to_matchable()
2436            })
2437            .to_matchable()
2438            .into(),
2439        ),
2440        (
2441            "GrantUsageDatashareStatementSegment".into(),
2442            NodeMatcher::new(SyntaxKind::GrantDatashareStatement, |_| {
2443                Sequence::new(vec![
2444                    one_of(vec![
2445                        Ref::keyword("GRANT").to_matchable(),
2446                        Ref::keyword("REVOKE").to_matchable(),
2447                    ])
2448                    .to_matchable(),
2449                    Ref::keyword("USAGE").to_matchable(),
2450                    Ref::keyword("ON").to_matchable(),
2451                    Ref::keyword("DATASHARE").to_matchable(),
2452                    Ref::new("ObjectReferenceSegment").to_matchable(),
2453                    one_of(vec![
2454                        Ref::keyword("TO").to_matchable(),
2455                        Ref::keyword("FROM").to_matchable(),
2456                    ])
2457                    .to_matchable(),
2458                    one_of(vec![
2459                        Sequence::new(vec![
2460                            Ref::keyword("NAMESPACE").to_matchable(),
2461                            Ref::new("QuotedLiteralSegment").to_matchable(),
2462                        ])
2463                        .to_matchable(),
2464                        Sequence::new(vec![
2465                            Ref::keyword("ACCOUNT").to_matchable(),
2466                            Sequence::new(vec![
2467                                Ref::new("QuotedLiteralSegment").to_matchable(),
2468                                Sequence::new(vec![
2469                                    Ref::keyword("VIA").to_matchable(),
2470                                    Ref::keyword("DATA").to_matchable(),
2471                                    Ref::keyword("CATALOG").to_matchable(),
2472                                ])
2473                                .config(|this| {
2474                                    this.optional();
2475                                })
2476                                .to_matchable(),
2477                            ])
2478                            .to_matchable(),
2479                        ])
2480                        .to_matchable(),
2481                    ])
2482                    .to_matchable(),
2483                ])
2484                .to_matchable()
2485            })
2486            .to_matchable()
2487            .into(),
2488        ),
2489        (
2490            "CreateRlsPolicyStatementSegment".into(),
2491            NodeMatcher::new(SyntaxKind::CreateRlsPolicyStatement, |_| {
2492                Sequence::new(vec![
2493                    Ref::keyword("CREATE").to_matchable(),
2494                    Ref::keyword("RLS").to_matchable(),
2495                    Ref::keyword("POLICY").to_matchable(),
2496                    Ref::new("ObjectReferenceSegment").to_matchable(),
2497                    Sequence::new(vec![
2498                        Ref::keyword("WITH").to_matchable(),
2499                        Bracketed::new(vec![
2500                            Delimited::new(vec![
2501                                Sequence::new(vec![
2502                                    Ref::new("ColumnReferenceSegment").to_matchable(),
2503                                    Ref::new("DatatypeSegment").to_matchable(),
2504                                ])
2505                                .to_matchable(),
2506                            ])
2507                            .to_matchable(),
2508                        ])
2509                        .to_matchable(),
2510                        Sequence::new(vec![
2511                            Ref::keyword("AS").optional().to_matchable(),
2512                            Ref::new("AliasExpressionSegment").to_matchable(),
2513                        ])
2514                        .config(|this| {
2515                            this.optional();
2516                        })
2517                        .to_matchable(),
2518                    ])
2519                    .config(|this| {
2520                        this.optional();
2521                    })
2522                    .to_matchable(),
2523                    Sequence::new(vec![
2524                        Ref::keyword("USING").to_matchable(),
2525                        Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
2526                            .to_matchable(),
2527                    ])
2528                    .to_matchable(),
2529                ])
2530                .to_matchable()
2531            })
2532            .to_matchable()
2533            .into(),
2534        ),
2535        (
2536            "ManageRlsPolicyStatementSegment".into(),
2537            NodeMatcher::new(SyntaxKind::ManageRlsPolicyStatement, |_| {
2538                Sequence::new(vec![
2539                    one_of(vec![
2540                        Ref::keyword("ATTACH").to_matchable(),
2541                        Ref::keyword("DETACH").to_matchable(),
2542                    ])
2543                    .to_matchable(),
2544                    Ref::keyword("RLS").to_matchable(),
2545                    Ref::keyword("POLICY").to_matchable(),
2546                    Ref::new("ObjectReferenceSegment").to_matchable(),
2547                    Ref::keyword("ON").to_matchable(),
2548                    Ref::keyword("TABLE").optional().to_matchable(),
2549                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
2550                        .to_matchable(),
2551                    one_of(vec![
2552                        Ref::keyword("TO").to_matchable(),
2553                        Ref::keyword("FROM").to_matchable(),
2554                    ])
2555                    .to_matchable(),
2556                    Delimited::new(vec![
2557                        one_of(vec![
2558                            Sequence::new(vec![
2559                                Ref::keyword("ROLE").optional().to_matchable(),
2560                                Ref::new("RoleReferenceSegment").to_matchable(),
2561                            ])
2562                            .to_matchable(),
2563                            Ref::keyword("PUBLIC").to_matchable(),
2564                        ])
2565                        .to_matchable(),
2566                    ])
2567                    .to_matchable(),
2568                ])
2569                .to_matchable()
2570            })
2571            .to_matchable()
2572            .into(),
2573        ),
2574        (
2575            "DropRlsPolicyStatementSegment".into(),
2576            NodeMatcher::new(SyntaxKind::DropRlsPolicyStatement, |_| {
2577                Sequence::new(vec![
2578                    Ref::keyword("DROP").to_matchable(),
2579                    Ref::keyword("RLS").to_matchable(),
2580                    Ref::keyword("POLICY").to_matchable(),
2581                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2582                    Ref::new("ObjectReferenceSegment").to_matchable(),
2583                    one_of(vec![
2584                        Ref::keyword("CASCADE").to_matchable(),
2585                        Ref::keyword("RESTRICT").to_matchable(),
2586                    ])
2587                    .config(|this| {
2588                        this.optional();
2589                    })
2590                    .to_matchable(),
2591                ])
2592                .to_matchable()
2593            })
2594            .to_matchable()
2595            .into(),
2596        ),
2597        (
2598            "AnalyzeCompressionStatementSegment".into(),
2599            NodeMatcher::new(SyntaxKind::AnalyzeCompressionStatement, |_| {
2600                Sequence::new(vec![
2601                    one_of(vec![
2602                        Ref::keyword("ANALYZE").to_matchable(),
2603                        Ref::keyword("ANALYSE").to_matchable(),
2604                    ])
2605                    .to_matchable(),
2606                    Ref::keyword("COMPRESSION").to_matchable(),
2607                    Sequence::new(vec![
2608                        Ref::new("TableReferenceSegment").to_matchable(),
2609                        Bracketed::new(vec![
2610                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
2611                                .to_matchable(),
2612                        ])
2613                        .config(|this| {
2614                            this.optional();
2615                        })
2616                        .to_matchable(),
2617                        Sequence::new(vec![
2618                            Ref::keyword("COMPROWS").to_matchable(),
2619                            Ref::new("NumericLiteralSegment").to_matchable(),
2620                        ])
2621                        .config(|this| {
2622                            this.optional();
2623                        })
2624                        .to_matchable(),
2625                    ])
2626                    .config(|this| {
2627                        this.optional();
2628                    })
2629                    .to_matchable(),
2630                ])
2631                .to_matchable()
2632            })
2633            .to_matchable()
2634            .into(),
2635        ),
2636    ]);
2637    redshift_dialect.replace_grammar(
2638        "VacuumStatementSegment",
2639        Sequence::new(vec![
2640            Ref::keyword("VACUUM").to_matchable(),
2641            one_of(vec![
2642                Ref::keyword("FULL").to_matchable(),
2643                Ref::keyword("REINDEX").to_matchable(),
2644                Ref::keyword("RECLUSTER").to_matchable(),
2645                Sequence::new(vec![
2646                    one_of(vec![
2647                        Ref::keyword("SORT").to_matchable(),
2648                        Ref::keyword("DELETE").to_matchable(),
2649                    ])
2650                    .to_matchable(),
2651                    Ref::keyword("ONLY").to_matchable(),
2652                ])
2653                .to_matchable(),
2654            ])
2655            .config(|this| {
2656                this.optional();
2657            })
2658            .to_matchable(),
2659            Ref::new("TableReferenceSegment").optional().to_matchable(),
2660            Sequence::new(vec![
2661                Ref::keyword("TO").to_matchable(),
2662                Ref::new("NumericLiteralSegment").to_matchable(),
2663                Ref::keyword("PERCENT").to_matchable(),
2664            ])
2665            .config(|this| {
2666                this.optional();
2667            })
2668            .to_matchable(),
2669            Ref::keyword("BOOST").optional().to_matchable(),
2670        ])
2671        .to_matchable(),
2672    );
2673
2674    redshift_dialect.add([]);
2675
2676    redshift_dialect.replace_grammar(
2677        "StatementSegment",
2678        postgres_dialect
2679            .grammar("StatementSegment")
2680            .match_grammar(&postgres_dialect)
2681            .unwrap()
2682            .copy(
2683                Some(vec![
2684                    Ref::new("CreateLibraryStatementSegment").to_matchable(),
2685                    Ref::new("CreateGroupStatementSegment").to_matchable(),
2686                    Ref::new("AlterUserStatementSegment").to_matchable(),
2687                    Ref::new("AlterGroupStatementSegment").to_matchable(),
2688                    Ref::new("CreateExternalTableAsStatementSegment").to_matchable(),
2689                    Ref::new("CreateExternalTableStatementSegment").to_matchable(),
2690                    Ref::new("CreateExternalSchemaStatementSegment").to_matchable(),
2691                    Ref::new("DataFormatSegment").to_matchable(),
2692                    Ref::new("UnloadStatementSegment").to_matchable(),
2693                    Ref::new("CopyStatementSegment").to_matchable(),
2694                    Ref::new("ShowModelStatementSegment").to_matchable(),
2695                    Ref::new("CreateDatashareStatementSegment").to_matchable(),
2696                    Ref::new("DescDatashareStatementSegment").to_matchable(),
2697                    Ref::new("DropDatashareStatementSegment").to_matchable(),
2698                    Ref::new("ShowDatasharesStatementSegment").to_matchable(),
2699                    Ref::new("AltereDatashareStatementSegment").to_matchable(),
2700                    Ref::new("DeclareStatementSegment").to_matchable(),
2701                    Ref::new("FetchStatementSegment").to_matchable(),
2702                    Ref::new("CloseStatementSegment").to_matchable(),
2703                    Ref::new("AnalyzeCompressionStatementSegment").to_matchable(),
2704                    Ref::new("AlterProcedureStatementSegment").to_matchable(),
2705                    Ref::new("CallStatementSegment").to_matchable(),
2706                    Ref::new("CreateRlsPolicyStatementSegment").to_matchable(),
2707                    Ref::new("ManageRlsPolicyStatementSegment").to_matchable(),
2708                    Ref::new("DropRlsPolicyStatementSegment").to_matchable(),
2709                    Ref::new("CreateExternalFunctionStatementSegment").to_matchable(),
2710                    Ref::new("GrantUsageDatashareStatementSegment").to_matchable(),
2711                ]),
2712                None,
2713                None,
2714                None,
2715                Vec::new(),
2716                false,
2717            ),
2718    );
2719
2720    redshift_dialect.add([
2721        (
2722            "PartitionedBySegment".into(),
2723            NodeMatcher::new(SyntaxKind::PartitionedBySegment, |_| {
2724                Sequence::new(vec![
2725                    Ref::keyword("PARTITIONED").to_matchable(),
2726                    Ref::keyword("BY").to_matchable(),
2727                    Bracketed::new(vec![
2728                        Delimited::new(vec![
2729                            Sequence::new(vec![
2730                                Ref::new("ColumnReferenceSegment").to_matchable(),
2731                                Ref::new("DatatypeSegment").optional().to_matchable(),
2732                            ])
2733                            .to_matchable(),
2734                        ])
2735                        .to_matchable(),
2736                    ])
2737                    .to_matchable(),
2738                ])
2739                .to_matchable()
2740            })
2741            .to_matchable()
2742            .into(),
2743        ),
2744        (
2745            "RowFormatDelimitedSegment".into(),
2746            NodeMatcher::new(SyntaxKind::RowFormatDelimitedSegment, |_| {
2747                any_set_of(vec![
2748                    Sequence::new(vec![
2749                        Ref::keyword("FIELDS").to_matchable(),
2750                        Ref::keyword("TERMINATED").to_matchable(),
2751                        Ref::keyword("BY").to_matchable(),
2752                        Ref::new("QuotedLiteralSegment").to_matchable(),
2753                    ])
2754                    .to_matchable(),
2755                    Sequence::new(vec![
2756                        Ref::keyword("LINES").to_matchable(),
2757                        Ref::keyword("TERMINATED").to_matchable(),
2758                        Ref::keyword("BY").to_matchable(),
2759                        Ref::new("QuotedLiteralSegment").to_matchable(),
2760                    ])
2761                    .to_matchable(),
2762                ])
2763                .config(|this| {
2764                    this.optional();
2765                })
2766                .to_matchable()
2767            })
2768            .to_matchable()
2769            .into(),
2770        ),
2771    ]);
2772
2773    redshift_dialect.replace_grammar(
2774        "CreateUserStatementSegment",
2775        Sequence::new(vec![
2776            Ref::keyword("CREATE").to_matchable(),
2777            Ref::keyword("USER").to_matchable(),
2778            Ref::new("RoleReferenceSegment").to_matchable(),
2779            Ref::keyword("WITH").optional().to_matchable(),
2780            Ref::keyword("PASSWORD").to_matchable(),
2781            one_of(vec![
2782                Ref::new("QuotedLiteralSegment").to_matchable(),
2783                Ref::keyword("DISABLE").to_matchable(),
2784            ])
2785            .to_matchable(),
2786            any_set_of(vec![
2787                one_of(vec![
2788                    Ref::keyword("CREATEDB").to_matchable(),
2789                    Ref::keyword("NOCREATEDB").to_matchable(),
2790                ])
2791                .to_matchable(),
2792                one_of(vec![
2793                    Ref::keyword("CREATEUSER").to_matchable(),
2794                    Ref::keyword("NOCREATEUSER").to_matchable(),
2795                ])
2796                .to_matchable(),
2797                Sequence::new(vec![
2798                    Ref::keyword("SYSLOG").to_matchable(),
2799                    Ref::keyword("ACCESS").to_matchable(),
2800                    one_of(vec![
2801                        Ref::keyword("RESTRICTED").to_matchable(),
2802                        Ref::keyword("UNRESTRICTED").to_matchable(),
2803                    ])
2804                    .to_matchable(),
2805                ])
2806                .to_matchable(),
2807                Sequence::new(vec![
2808                    Ref::keyword("IN").to_matchable(),
2809                    Ref::keyword("GROUP").to_matchable(),
2810                    Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
2811                        .to_matchable(),
2812                ])
2813                .to_matchable(),
2814                Sequence::new(vec![
2815                    Ref::keyword("VALID").to_matchable(),
2816                    Ref::keyword("UNTIL").to_matchable(),
2817                    Ref::new("QuotedLiteralSegment").to_matchable(),
2818                ])
2819                .to_matchable(),
2820                Sequence::new(vec![
2821                    Ref::keyword("CONNECTION").to_matchable(),
2822                    Ref::keyword("LIMIT").to_matchable(),
2823                    one_of(vec![
2824                        Ref::new("NumericLiteralSegment").to_matchable(),
2825                        Ref::keyword("UNLIMITED").to_matchable(),
2826                    ])
2827                    .to_matchable(),
2828                ])
2829                .to_matchable(),
2830                Sequence::new(vec![
2831                    Ref::keyword("SESSION").to_matchable(),
2832                    Ref::keyword("TIMEOUT").to_matchable(),
2833                    Ref::new("NumericLiteralSegment").to_matchable(),
2834                ])
2835                .to_matchable(),
2836            ])
2837            .to_matchable(),
2838        ])
2839        .to_matchable(),
2840    );
2841    redshift_dialect.add([
2842        (
2843            "CreateGroupStatementSegment".into(),
2844            NodeMatcher::new(SyntaxKind::CreateGroup, |_| {
2845                Sequence::new(vec![
2846                    Ref::keyword("CREATE").to_matchable(),
2847                    Ref::keyword("GROUP").to_matchable(),
2848                    Ref::new("ObjectReferenceSegment").to_matchable(),
2849                    Sequence::new(vec![
2850                        Ref::keyword("WITH").optional().to_matchable(),
2851                        Ref::keyword("USER").to_matchable(),
2852                        Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
2853                            .to_matchable(),
2854                    ])
2855                    .config(|this| {
2856                        this.optional();
2857                    })
2858                    .to_matchable(),
2859                ])
2860                .to_matchable()
2861            })
2862            .to_matchable()
2863            .into(),
2864        ),
2865        (
2866            "AlterUserStatementSegment".into(),
2867            NodeMatcher::new(SyntaxKind::AlterUserStatement, |_| {
2868                Sequence::new(vec![
2869                    Ref::keyword("ALTER").to_matchable(),
2870                    Ref::keyword("USER").to_matchable(),
2871                    Ref::new("RoleReferenceSegment").to_matchable(),
2872                    Ref::keyword("WITH").optional().to_matchable(),
2873                    any_set_of(vec![
2874                        one_of(vec![
2875                            Ref::keyword("CREATEDB").to_matchable(),
2876                            Ref::keyword("NOCREATEDB").to_matchable(),
2877                        ])
2878                        .to_matchable(),
2879                        one_of(vec![
2880                            Ref::keyword("CREATEUSER").to_matchable(),
2881                            Ref::keyword("NOCREATEUSER").to_matchable(),
2882                        ])
2883                        .to_matchable(),
2884                        Sequence::new(vec![
2885                            Ref::keyword("SYSLOG").to_matchable(),
2886                            Ref::keyword("ACCESS").to_matchable(),
2887                            one_of(vec![
2888                                Ref::keyword("RESTRICTED").to_matchable(),
2889                                Ref::keyword("UNRESTRICTED").to_matchable(),
2890                            ])
2891                            .to_matchable(),
2892                        ])
2893                        .to_matchable(),
2894                        Sequence::new(vec![
2895                            Ref::keyword("PASSWORD").to_matchable(),
2896                            one_of(vec![
2897                                Ref::new("QuotedLiteralSegment").to_matchable(),
2898                                Ref::keyword("DISABLE").to_matchable(),
2899                            ])
2900                            .to_matchable(),
2901                            Sequence::new(vec![
2902                                Ref::keyword("VALID").to_matchable(),
2903                                Ref::keyword("UNTIL").to_matchable(),
2904                                Ref::new("QuotedLiteralSegment").to_matchable(),
2905                            ])
2906                            .config(|this| {
2907                                this.optional();
2908                            })
2909                            .to_matchable(),
2910                        ])
2911                        .to_matchable(),
2912                        Sequence::new(vec![
2913                            Ref::keyword("RENAME").to_matchable(),
2914                            Ref::keyword("TO").to_matchable(),
2915                            Ref::new("ObjectReferenceSegment").to_matchable(),
2916                        ])
2917                        .to_matchable(),
2918                        Sequence::new(vec![
2919                            Ref::keyword("CONNECTION").to_matchable(),
2920                            Ref::keyword("LIMIT").to_matchable(),
2921                            one_of(vec![
2922                                Ref::new("NumericLiteralSegment").to_matchable(),
2923                                Ref::keyword("UNLIMITED").to_matchable(),
2924                            ])
2925                            .to_matchable(),
2926                        ])
2927                        .to_matchable(),
2928                        one_of(vec![
2929                            Sequence::new(vec![
2930                                Ref::keyword("SESSION").to_matchable(),
2931                                Ref::keyword("TIMEOUT").to_matchable(),
2932                                Ref::new("NumericLiteralSegment").to_matchable(),
2933                            ])
2934                            .to_matchable(),
2935                            Sequence::new(vec![
2936                                Ref::keyword("RESET").to_matchable(),
2937                                Ref::keyword("SESSION").to_matchable(),
2938                                Ref::keyword("TIMEOUT").to_matchable(),
2939                            ])
2940                            .to_matchable(),
2941                        ])
2942                        .to_matchable(),
2943                        one_of(vec![
2944                            Sequence::new(vec![
2945                                Ref::keyword("SET").to_matchable(),
2946                                Ref::new("ObjectReferenceSegment").to_matchable(),
2947                                one_of(vec![
2948                                    Ref::keyword("TO").to_matchable(),
2949                                    Ref::new("EqualsSegment").to_matchable(),
2950                                ])
2951                                .to_matchable(),
2952                                one_of(vec![
2953                                    Ref::keyword("DEFAULT").to_matchable(),
2954                                    Ref::new("LiteralGrammar").to_matchable(),
2955                                ])
2956                                .to_matchable(),
2957                            ])
2958                            .to_matchable(),
2959                            Sequence::new(vec![
2960                                Ref::keyword("RESET").to_matchable(),
2961                                Ref::new("ObjectReferenceSegment").to_matchable(),
2962                            ])
2963                            .to_matchable(),
2964                        ])
2965                        .to_matchable(),
2966                    ])
2967                    .config(|this| {
2968                        this.min_times = 1;
2969                    })
2970                    .to_matchable(),
2971                ])
2972                .to_matchable()
2973            })
2974            .to_matchable()
2975            .into(),
2976        ),
2977        (
2978            "AlterGroupStatementSegment".into(),
2979            NodeMatcher::new(SyntaxKind::AlterGroup, |_| {
2980                Sequence::new(vec![
2981                    Ref::keyword("ALTER").to_matchable(),
2982                    Ref::keyword("GROUP").to_matchable(),
2983                    Ref::new("ObjectReferenceSegment").to_matchable(),
2984                    one_of(vec![
2985                        Sequence::new(vec![
2986                            one_of(vec![
2987                                Ref::keyword("ADD").to_matchable(),
2988                                Ref::keyword("DROP").to_matchable(),
2989                            ])
2990                            .to_matchable(),
2991                            Ref::keyword("USER").to_matchable(),
2992                            Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
2993                                .to_matchable(),
2994                        ])
2995                        .to_matchable(),
2996                        Sequence::new(vec![
2997                            Ref::keyword("RENAME").to_matchable(),
2998                            Ref::keyword("TO").to_matchable(),
2999                            Ref::new("ObjectReferenceSegment").to_matchable(),
3000                        ])
3001                        .to_matchable(),
3002                    ])
3003                    .to_matchable(),
3004                ])
3005                .to_matchable()
3006            })
3007            .to_matchable()
3008            .into(),
3009        ),
3010        (
3011            "TransactionStatementSegment".into(),
3012            NodeMatcher::new(SyntaxKind::TransactionStatement, |_| {
3013                Sequence::new(vec![
3014                    one_of(vec![
3015                        Ref::keyword("BEGIN").to_matchable(),
3016                        Ref::keyword("START").to_matchable(),
3017                        Ref::keyword("COMMIT").to_matchable(),
3018                        Ref::keyword("END").to_matchable(),
3019                        Ref::keyword("ROLLBACK").to_matchable(),
3020                        Ref::keyword("ABORT").to_matchable(),
3021                    ])
3022                    .to_matchable(),
3023                    one_of(vec![
3024                        Ref::keyword("TRANSACTION").to_matchable(),
3025                        Ref::keyword("WORK").to_matchable(),
3026                    ])
3027                    .config(|this| {
3028                        this.optional();
3029                    })
3030                    .to_matchable(),
3031                    Sequence::new(vec![
3032                        Ref::keyword("ISOLATION").to_matchable(),
3033                        Ref::keyword("LEVEL").to_matchable(),
3034                        one_of(vec![
3035                            Ref::keyword("SERIALIZABLE").to_matchable(),
3036                            Sequence::new(vec![
3037                                Ref::keyword("READ").to_matchable(),
3038                                Ref::keyword("COMMITTED").to_matchable(),
3039                            ])
3040                            .to_matchable(),
3041                            Sequence::new(vec![
3042                                Ref::keyword("READ").to_matchable(),
3043                                Ref::keyword("UNCOMMITTED").to_matchable(),
3044                            ])
3045                            .to_matchable(),
3046                            Sequence::new(vec![
3047                                Ref::keyword("REPEATABLE").to_matchable(),
3048                                Ref::keyword("READ").to_matchable(),
3049                            ])
3050                            .to_matchable(),
3051                        ])
3052                        .to_matchable(),
3053                    ])
3054                    .config(|this| {
3055                        this.optional();
3056                    })
3057                    .to_matchable(),
3058                    one_of(vec![
3059                        Sequence::new(vec![
3060                            Ref::keyword("READ").to_matchable(),
3061                            Ref::keyword("ONLY").to_matchable(),
3062                        ])
3063                        .to_matchable(),
3064                        Sequence::new(vec![
3065                            Ref::keyword("READ").to_matchable(),
3066                            Ref::keyword("WRITE").to_matchable(),
3067                        ])
3068                        .to_matchable(),
3069                    ])
3070                    .config(|this| {
3071                        this.optional();
3072                    })
3073                    .to_matchable(),
3074                ])
3075                .to_matchable()
3076            })
3077            .to_matchable()
3078            .into(),
3079        ),
3080        (
3081            "AlterSchemaStatementSegment".into(),
3082            NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_| {
3083                Sequence::new(vec![
3084                    Ref::keyword("ALTER").to_matchable(),
3085                    Ref::keyword("SCHEMA").to_matchable(),
3086                    Ref::new("SchemaReferenceSegment").to_matchable(),
3087                    one_of(vec![
3088                        Sequence::new(vec![
3089                            Ref::keyword("RENAME").to_matchable(),
3090                            Ref::keyword("TO").to_matchable(),
3091                            Ref::new("SchemaReferenceSegment").to_matchable(),
3092                        ])
3093                        .to_matchable(),
3094                        Sequence::new(vec![
3095                            Ref::keyword("OWNER").to_matchable(),
3096                            Ref::keyword("TO").to_matchable(),
3097                            Ref::new("RoleReferenceSegment").to_matchable(),
3098                        ])
3099                        .to_matchable(),
3100                        Ref::new("QuotaGrammar").to_matchable(),
3101                    ])
3102                    .to_matchable(),
3103                ])
3104                .to_matchable()
3105            })
3106            .to_matchable()
3107            .into(),
3108        ),
3109        (
3110            "LockTableStatementSegment".into(),
3111            NodeMatcher::new(SyntaxKind::LockTableStatement, |_| {
3112                Sequence::new(vec![
3113                    Ref::keyword("LOCK").to_matchable(),
3114                    Ref::keyword("TABLE").optional().to_matchable(),
3115                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
3116                        .to_matchable(),
3117                ])
3118                .to_matchable()
3119            })
3120            .to_matchable()
3121            .into(),
3122        ),
3123    ]);
3124
3125    redshift_dialect.replace_grammar(
3126        "TableExpressionSegment",
3127        ansi_dialect
3128            .grammar("TableExpressionSegment")
3129            .match_grammar(&ansi_dialect)
3130            .unwrap()
3131            .copy(
3132                Some(vec![
3133                    Ref::new("ObjectUnpivotSegment").optional().to_matchable(),
3134                    Ref::new("ArrayUnnestSegment").optional().to_matchable(),
3135                ]),
3136                None,
3137                Some(Ref::new("TableReferenceSegment").to_matchable()),
3138                None,
3139                Vec::new(),
3140                false,
3141            ),
3142    );
3143
3144    redshift_dialect.add([(
3145        "ObjectUnpivotSegment".into(),
3146        NodeMatcher::new(SyntaxKind::ObjectUnpivoting, |_| {
3147            Sequence::new(vec![
3148                Ref::keyword("UNPIVOT").to_matchable(),
3149                Ref::new("ObjectReferenceSegment").to_matchable(),
3150                Ref::keyword("AS").to_matchable(),
3151                Ref::new("SingleIdentifierGrammar").to_matchable(),
3152                Ref::keyword("AT").to_matchable(),
3153                Ref::new("SingleIdentifierGrammar").to_matchable(),
3154            ])
3155            .to_matchable()
3156        })
3157        .to_matchable()
3158        .into(),
3159    )]);
3160
3161    redshift_dialect.replace_grammar(
3162        "ArrayAccessorSegment",
3163        Sequence::new(vec![
3164            AnyNumberOf::new(vec![
3165                Bracketed::new(vec![
3166                    one_of(vec![
3167                        Ref::new("NumericLiteralSegment").to_matchable(),
3168                        Ref::new("ExpressionSegment").to_matchable(),
3169                    ])
3170                    .to_matchable(),
3171                ])
3172                .config(|this| {
3173                    this.bracket_type = "square";
3174                })
3175                .to_matchable(),
3176            ])
3177            .to_matchable(),
3178        ])
3179        .to_matchable(),
3180    );
3181
3182    redshift_dialect.add([
3183        (
3184            "ArrayUnnestSegment".into(),
3185            NodeMatcher::new(SyntaxKind::ArrayUnnesting, |_| {
3186                Sequence::new(vec![
3187                    Ref::new("ObjectReferenceSegment").to_matchable(),
3188                    Ref::keyword("AS").to_matchable(),
3189                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3190                    Ref::keyword("AT").to_matchable(),
3191                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3192                ])
3193                .to_matchable()
3194            })
3195            .to_matchable()
3196            .into(),
3197        ),
3198        (
3199            "CallStatementSegment".into(),
3200            NodeMatcher::new(SyntaxKind::CallStatement, |_| {
3201                Sequence::new(vec![
3202                    Ref::keyword("CALL").to_matchable(),
3203                    Ref::new("FunctionSegment").to_matchable(),
3204                ])
3205                .to_matchable()
3206            })
3207            .to_matchable()
3208            .into(),
3209        ),
3210    ]);
3211
3212    redshift_dialect.replace_grammar(
3213        "SelectClauseModifierSegment",
3214        postgres_dialect
3215            .grammar("SelectClauseModifierSegment")
3216            .match_grammar(&postgres_dialect)
3217            .unwrap()
3218            .copy(
3219                Some(vec![
3220                    Sequence::new(vec![
3221                        Ref::keyword("TOP").to_matchable(),
3222                        Ref::new("NumericLiteralSegment").to_matchable(),
3223                    ])
3224                    .to_matchable(),
3225                ]),
3226                None,
3227                None,
3228                None,
3229                Vec::new(),
3230                false,
3231            ),
3232    );
3233
3234    redshift_dialect.add([(
3235        "ConvertFunctionNameSegment".into(),
3236        NodeMatcher::new(SyntaxKind::FunctionName, |_| {
3237            Sequence::new(vec![Ref::keyword("CONVERT").to_matchable()]).to_matchable()
3238        })
3239        .to_matchable()
3240        .into(),
3241    )]);
3242
3243    redshift_dialect.replace_grammar(
3244        "FunctionSegment",
3245        one_of(vec![
3246            Sequence::new(vec![
3247                Sequence::new(vec![
3248                    Ref::new("DatePartFunctionNameSegment").to_matchable(),
3249                    Bracketed::new(vec![
3250                        Delimited::new(vec![
3251                            Ref::new("DatetimeUnitSegment").to_matchable(),
3252                            Ref::new("FunctionContentsGrammar")
3253                                .optional()
3254                                .to_matchable(),
3255                        ])
3256                        .to_matchable(),
3257                    ])
3258                    .config(|this| {
3259                        this.parse_mode = ParseMode::Greedy;
3260                    })
3261                    .to_matchable(),
3262                ])
3263                .to_matchable(),
3264            ])
3265            .to_matchable(),
3266            Sequence::new(vec![
3267                Sequence::new(vec![
3268                    one_of(vec![
3269                        Ref::new("FunctionNameSegment")
3270                            .exclude(one_of(vec![
3271                                Ref::new("DatePartFunctionNameSegment").to_matchable(),
3272                                Ref::new("ValuesClauseSegment").to_matchable(),
3273                                Ref::new("ConvertFunctionNameSegment").to_matchable(),
3274                            ]))
3275                            .to_matchable(),
3276                        Sequence::new(vec![
3277                            Ref::keyword("APPROXIMATE").to_matchable(),
3278                            Ref::new("FunctionNameSegment")
3279                                .exclude(one_of(vec![
3280                                    Ref::new("DatePartFunctionNameSegment").to_matchable(),
3281                                    Ref::new("ValuesClauseSegment").to_matchable(),
3282                                    Ref::new("ConvertFunctionNameSegment").to_matchable(),
3283                                ]))
3284                                .to_matchable(),
3285                        ])
3286                        .to_matchable(),
3287                    ])
3288                    .to_matchable(),
3289                    Bracketed::new(vec![
3290                        Ref::new("FunctionContentsGrammar")
3291                            .optional()
3292                            .to_matchable(),
3293                    ])
3294                    .config(|this| {
3295                        this.parse_mode = ParseMode::Greedy;
3296                    })
3297                    .to_matchable(),
3298                ])
3299                .to_matchable(),
3300                Ref::new("PostFunctionGrammar").optional().to_matchable(),
3301            ])
3302            .to_matchable(),
3303            Sequence::new(vec![
3304                Ref::new("ConvertFunctionNameSegment").to_matchable(),
3305                Bracketed::new(vec![
3306                    Ref::new("DatatypeSegment").to_matchable(),
3307                    Ref::new("CommaSegment").to_matchable(),
3308                    Ref::new("ExpressionSegment").to_matchable(),
3309                ])
3310                .to_matchable(),
3311            ])
3312            .to_matchable(),
3313        ])
3314        .to_matchable(),
3315    );
3316
3317    redshift_dialect.add([]);
3318
3319    redshift_dialect.replace_grammar(
3320        "FromClauseSegment",
3321        Sequence::new(vec![
3322            Ref::keyword("FROM").to_matchable(),
3323            Delimited::new(vec![
3324                optionally_bracketed(vec![Ref::new("FromExpressionSegment").to_matchable()])
3325                    .to_matchable(),
3326            ])
3327            .to_matchable(),
3328        ])
3329        .to_matchable(),
3330    );
3331
3332    redshift_dialect.add([(
3333        "CreateViewStatementSegment".into(),
3334        NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| {
3335            Sequence::new(vec![
3336                Ref::keyword("CREATE").to_matchable(),
3337                Ref::new("OrReplaceGrammar").optional().to_matchable(),
3338                Ref::keyword("VIEW").to_matchable(),
3339                Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3340                Ref::new("TableReferenceSegment").to_matchable(),
3341                Ref::new("BracketedColumnReferenceListGrammar")
3342                    .optional()
3343                    .to_matchable(),
3344                Ref::keyword("AS").to_matchable(),
3345                optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
3346                    .to_matchable(),
3347                Ref::new("WithNoSchemaBindingClauseSegment")
3348                    .optional()
3349                    .to_matchable(),
3350            ])
3351            .to_matchable()
3352        })
3353        .to_matchable()
3354        .into(),
3355    )]);
3356    redshift_dialect.replace_grammar(
3357        "CreateMaterializedViewStatementSegment",
3358        Sequence::new(vec![
3359            Ref::keyword("CREATE").to_matchable(),
3360            Ref::keyword("MATERIALIZED").to_matchable(),
3361            Ref::keyword("VIEW").to_matchable(),
3362            Ref::new("TableReferenceSegment").to_matchable(),
3363            Sequence::new(vec![
3364                Ref::keyword("BACKUP").to_matchable(),
3365                one_of(vec![
3366                    Ref::keyword("YES").to_matchable(),
3367                    Ref::keyword("NO").to_matchable(),
3368                ])
3369                .to_matchable(),
3370            ])
3371            .config(|this| {
3372                this.optional();
3373            })
3374            .to_matchable(),
3375            Ref::new("TableAttributeSegment").optional().to_matchable(),
3376            Sequence::new(vec![
3377                Ref::keyword("AUTO").to_matchable(),
3378                Ref::keyword("REFRESH").to_matchable(),
3379                one_of(vec![
3380                    Ref::keyword("YES").to_matchable(),
3381                    Ref::keyword("NO").to_matchable(),
3382                ])
3383                .to_matchable(),
3384            ])
3385            .config(|this| {
3386                this.optional();
3387            })
3388            .to_matchable(),
3389            Ref::keyword("AS").to_matchable(),
3390            one_of(vec![
3391                optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
3392                    .to_matchable(),
3393                optionally_bracketed(vec![
3394                    Sequence::new(vec![
3395                        Ref::keyword("TABLE").to_matchable(),
3396                        Ref::new("TableReferenceSegment").to_matchable(),
3397                    ])
3398                    .to_matchable(),
3399                ])
3400                .to_matchable(),
3401                Ref::new("ValuesClauseSegment").to_matchable(),
3402                optionally_bracketed(vec![
3403                    Sequence::new(vec![
3404                        Ref::keyword("EXECUTE").to_matchable(),
3405                        Ref::new("FunctionSegment").to_matchable(),
3406                    ])
3407                    .to_matchable(),
3408                ])
3409                .to_matchable(),
3410            ])
3411            .to_matchable(),
3412            Ref::new("WithDataClauseSegment").optional().to_matchable(),
3413        ])
3414        .to_matchable(),
3415    );
3416    redshift_dialect.add([
3417        (
3418            "CreateExternalFunctionStatementSegment".into(),
3419            NodeMatcher::new(SyntaxKind::CreateExternalFunctionStatement, |_| {
3420                Sequence::new(vec![
3421                    Ref::keyword("CREATE").to_matchable(),
3422                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
3423                    Ref::keyword("EXTERNAL").to_matchable(),
3424                    Ref::keyword("FUNCTION").to_matchable(),
3425                    Ref::new("FunctionNameSegment").to_matchable(),
3426                    Bracketed::new(vec![
3427                        Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()])
3428                            .config(|this| {
3429                                this.optional();
3430                            })
3431                            .to_matchable(),
3432                    ])
3433                    .to_matchable(),
3434                    Ref::keyword("RETURNS").to_matchable(),
3435                    Ref::new("DatatypeSegment").to_matchable(),
3436                    one_of(vec![
3437                        Ref::keyword("VOLATILE").to_matchable(),
3438                        Ref::keyword("STABLE").to_matchable(),
3439                        Ref::keyword("IMMUTABLE").to_matchable(),
3440                    ])
3441                    .to_matchable(),
3442                    one_of(vec![
3443                        Ref::keyword("LAMBDA").to_matchable(),
3444                        Ref::keyword("SAGEMAKER").to_matchable(),
3445                    ])
3446                    .to_matchable(),
3447                    Ref::new("QuotedLiteralSegment").to_matchable(),
3448                    Ref::keyword("IAM_ROLE").to_matchable(),
3449                    one_of(vec![
3450                        Ref::keyword("DEFAULT").to_matchable(),
3451                        Ref::new("QuotedLiteralSegment").to_matchable(),
3452                    ])
3453                    .to_matchable(),
3454                    Sequence::new(vec![
3455                        Ref::keyword("RETRY_TIMEOUT").to_matchable(),
3456                        Ref::new("NumericLiteralSegment").to_matchable(),
3457                    ])
3458                    .config(|this| {
3459                        this.optional();
3460                    })
3461                    .to_matchable(),
3462                ])
3463                .to_matchable()
3464            })
3465            .to_matchable()
3466            .into(),
3467        ),
3468        (
3469            "QualifyClauseSegment".into(),
3470            NodeMatcher::new(SyntaxKind::QualifyClause, |_| {
3471                Sequence::new(vec![
3472                    Ref::keyword("QUALIFY").to_matchable(),
3473                    MetaSegment::indent().to_matchable(),
3474                    Ref::new("ExpressionSegment").to_matchable(),
3475                    MetaSegment::dedent().to_matchable(),
3476                ])
3477                .to_matchable()
3478            })
3479            .to_matchable()
3480            .into(),
3481        ),
3482    ]);
3483    redshift_dialect.replace_grammar(
3484        "SelectStatementSegment",
3485        postgres_dialect
3486            .grammar("SelectStatementSegment")
3487            .match_grammar(&postgres_dialect)
3488            .unwrap()
3489            .copy(
3490                Some(vec![
3491                    Ref::new("QualifyClauseSegment").optional().to_matchable(),
3492                ]),
3493                None,
3494                Some(Ref::new("OrderByClauseSegment").optional().to_matchable()),
3495                None,
3496                vec![Ref::new("SetOperatorSegment").to_matchable()],
3497                false,
3498            ),
3499    );
3500    redshift_dialect.add([]);
3501    redshift_dialect.replace_grammar(
3502        "UnorderedSelectStatementSegment",
3503        ansi_dialect
3504            .grammar("UnorderedSelectStatementSegment")
3505            .match_grammar(&ansi_dialect)
3506            .unwrap()
3507            .copy(
3508                Some(vec![
3509                    Ref::new("QualifyClauseSegment").optional().to_matchable(),
3510                ]),
3511                None,
3512                Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()),
3513                None,
3514                Vec::new(),
3515                false,
3516            ),
3517    );
3518
3519    redshift_dialect
3520}