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)]
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 fn supports_named_fn_args_with_assignment_operator(&self) -> bool {
51 true
52 }
53
54 // DuckDB uses this syntax for `STRUCT`s.
55 //
56 // https://duckdb.org/docs/sql/data_types/struct.html#creating-structs
57 fn supports_dictionary_syntax(&self) -> bool {
58 true
59 }
60
61 // DuckDB uses this syntax for `MAP`s.
62 //
63 // https://duckdb.org/docs/sql/data_types/map.html#creating-maps
64 fn support_map_literal_syntax(&self) -> bool {
65 true
66 }
67
68 /// See <https://duckdb.org/docs/sql/functions/lambda.html>
69 fn supports_lambda_functions(&self) -> bool {
70 true
71 }
72
73 // DuckDB is compatible with PostgreSQL syntax for this statement,
74 // although not all features may be implemented.
75 fn supports_explain_with_utility_options(&self) -> bool {
76 true
77 }
78
79 /// See DuckDB <https://duckdb.org/docs/sql/statements/load_and_install.html#load>
80 fn supports_load_extension(&self) -> bool {
81 true
82 }
83
84 // See DuckDB <https://duckdb.org/docs/sql/data_types/array.html#defining-an-array-field>
85 fn supports_array_typedef_with_brackets(&self) -> bool {
86 true
87 }
88
89 fn supports_from_first_select(&self) -> bool {
90 true
91 }
92
93 /// See DuckDB <https://duckdb.org/docs/sql/query_syntax/orderby.html#order-by-all-examples>
94 fn supports_order_by_all(&self) -> bool {
95 true
96 }
97}