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