Skip to main content

sqlparser/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, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct DuckDbDialect;
24
25// In most cases the redshift dialect is identical to [`PostgresSqlDialect`].
26impl Dialect for DuckDbDialect {
27    fn supports_trailing_commas(&self) -> bool {
28        true
29    }
30
31    fn is_identifier_start(&self, ch: char) -> bool {
32        ch.is_alphabetic() || ch == '_'
33    }
34
35    fn is_identifier_part(&self, ch: char) -> bool {
36        ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_'
37    }
38
39    /// See <https://duckdb.org/docs/stable/sql/dialect/keywords_and_identifiers>
40    fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
41        Some('"')
42    }
43
44    fn supports_filter_during_aggregation(&self) -> bool {
45        true
46    }
47
48    fn supports_group_by_expr(&self) -> bool {
49        true
50    }
51
52    fn supports_bitwise_shift_operators(&self) -> bool {
53        true
54    }
55
56    fn supports_named_fn_args_with_eq_operator(&self) -> bool {
57        true
58    }
59
60    fn supports_named_fn_args_with_assignment_operator(&self) -> bool {
61        true
62    }
63
64    // DuckDB uses this syntax for `STRUCT`s.
65    //
66    // https://duckdb.org/docs/sql/data_types/struct.html#creating-structs
67    fn supports_dictionary_syntax(&self) -> bool {
68        true
69    }
70
71    // DuckDB uses this syntax for `MAP`s.
72    //
73    // https://duckdb.org/docs/sql/data_types/map.html#creating-maps
74    fn support_map_literal_syntax(&self) -> bool {
75        true
76    }
77
78    /// See <https://duckdb.org/docs/stable/sql/functions/lambda>
79    fn supports_lambda_functions(&self) -> bool {
80        true
81    }
82
83    /// Returns true if this dialect allows the `EXTRACT` function to use single quotes in the part being extracted.
84    fn allow_extract_single_quotes(&self) -> bool {
85        true
86    }
87
88    // DuckDB is compatible with PostgreSQL syntax for this statement,
89    // although not all features may be implemented.
90    fn supports_explain_with_utility_options(&self) -> bool {
91        true
92    }
93
94    /// See DuckDB <https://duckdb.org/docs/sql/statements/load_and_install.html#load>
95    fn supports_load_extension(&self) -> bool {
96        true
97    }
98
99    // See DuckDB <https://duckdb.org/docs/sql/data_types/array.html#defining-an-array-field>
100    fn supports_array_typedef_with_brackets(&self) -> bool {
101        true
102    }
103
104    fn supports_from_first_select(&self) -> bool {
105        true
106    }
107
108    /// See DuckDB <https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples>
109    fn supports_order_by_all(&self) -> bool {
110        true
111    }
112
113    fn supports_select_wildcard_exclude(&self) -> bool {
114        true
115    }
116
117    /// DuckDB supports `NOTNULL` as an alias for `IS NOT NULL`,
118    /// see DuckDB Comparisons <https://duckdb.org/docs/stable/sql/expressions/comparison_operators#between-and-is-not-null>
119    fn supports_notnull_operator(&self) -> bool {
120        true
121    }
122
123    /// See <https://duckdb.org/docs/extensions/overview>
124    fn supports_install(&self) -> bool {
125        true
126    }
127
128    /// See <https://duckdb.org/docs/sql/statements/attach#detach-syntax>
129    fn supports_detach(&self) -> bool {
130        true
131    }
132
133    /// See <https://duckdb.org/docs/sql/query_syntax/select#replace-clause>
134    fn supports_select_wildcard_replace(&self) -> bool {
135        true
136    }
137
138    fn supports_comma_separated_trim(&self) -> bool {
139        true
140    }
141
142    fn supports_numeric_literal_underscores(&self) -> bool {
143        true
144    }
145}