sqltk_parser/dialect/
duckdb.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::dialect::Dialect;
19
20/// A [`Dialect`] for [DuckDB](https://duckdb.org/)
21#[derive(Debug, Default)]
22pub struct DuckDbDialect;
23
24// In most cases the redshift dialect is identical to [`PostgresSqlDialect`].
25impl Dialect for DuckDbDialect {
26    fn supports_trailing_commas(&self) -> bool {
27        true
28    }
29
30    fn is_identifier_start(&self, ch: char) -> bool {
31        ch.is_alphabetic() || ch == '_'
32    }
33
34    fn is_identifier_part(&self, ch: char) -> bool {
35        ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_'
36    }
37
38    fn supports_filter_during_aggregation(&self) -> bool {
39        true
40    }
41
42    fn supports_group_by_expr(&self) -> bool {
43        true
44    }
45
46    fn supports_named_fn_args_with_eq_operator(&self) -> bool {
47        true
48    }
49
50    // DuckDB uses this syntax for `STRUCT`s.
51    //
52    // https://duckdb.org/docs/sql/data_types/struct.html#creating-structs
53    fn supports_dictionary_syntax(&self) -> bool {
54        true
55    }
56
57    // DuckDB uses this syntax for `MAP`s.
58    //
59    // https://duckdb.org/docs/sql/data_types/map.html#creating-maps
60    fn support_map_literal_syntax(&self) -> bool {
61        true
62    }
63
64    // DuckDB is compatible with PostgreSQL syntax for this statement,
65    // although not all features may be implemented.
66    fn supports_explain_with_utility_options(&self) -> bool {
67        true
68    }
69}