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