duckdb.rs - source

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    fn supports_filter_during_aggregation(&self) -> bool {
40        true
41    }
42
43    fn supports_group_by_expr(&self) -> bool {
44        true
45    }
46
47    fn supports_bitwise_shift_operators(&self) -> bool {
48        true
49    }
50
51    fn supports_named_fn_args_with_eq_operator(&self) -> bool {
52        true
53    }
54
55    fn supports_named_fn_args_with_assignment_operator(&self) -> bool {
56        true
57    }
58
59    // DuckDB uses this syntax for `STRUCT`s.
60    //
61    // https://duckdb.org/docs/sql/data_types/struct.html#creating-structs
62    fn supports_dictionary_syntax(&self) -> bool {
63        true
64    }
65
66    // DuckDB uses this syntax for `MAP`s.
67    //
68    // https://duckdb.org/docs/sql/data_types/map.html#creating-maps
69    fn support_map_literal_syntax(&self) -> bool {
70        true
71    }
72
73    /// See <https://duckdb.org/docs/stable/sql/functions/lambda>
74    fn supports_lambda_functions(&self) -> bool {
75        true
76    }
77
78    /// Returns true if this dialect allows the `EXTRACT` function to use single quotes in the part being extracted.
79    fn allow_extract_single_quotes(&self) -> bool {
80        true
81    }
82
83    // DuckDB is compatible with PostgreSQL syntax for this statement,
84    // although not all features may be implemented.
85    fn supports_explain_with_utility_options(&self) -> bool {
86        true
87    }
88
89    /// See DuckDB <https://duckdb.org/docs/sql/statements/load_and_install.html#load>
90    fn supports_load_extension(&self) -> bool {
91        true
92    }
93
94    // See DuckDB <https://duckdb.org/docs/sql/data_types/array.html#defining-an-array-field>
95    fn supports_array_typedef_with_brackets(&self) -> bool {
96        true
97    }
98
99    fn supports_from_first_select(&self) -> bool {
100        true
101    }
102
103    /// See DuckDB <https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples>
104    fn supports_order_by_all(&self) -> bool {
105        true
106    }
107
108    fn supports_select_wildcard_exclude(&self) -> bool {
109        true
110    }
111
112    /// DuckDB supports `NOTNULL` as an alias for `IS NOT NULL`,
113    /// see DuckDB Comparisons <https://duckdb.org/docs/stable/sql/expressions/comparison_operators#between-and-is-not-null>
114    fn supports_notnull_operator(&self) -> bool {
115        true
116    }
117
118    /// See <https://duckdb.org/docs/extensions/overview>
119    fn supports_install(&self) -> bool {
120        true
121    }
122
123    /// See <https://duckdb.org/docs/sql/statements/attach#detach-syntax>
124    fn supports_detach(&self) -> bool {
125        true
126    }
127
128    /// See <https://duckdb.org/docs/sql/query_syntax/select#replace-clause>
129    fn supports_select_wildcard_replace(&self) -> bool {
130        true
131    }
132}