diff --git a/crates/lib-dialects/src/duckdb.rs b/crates/lib-dialects/src/duckdb.rs index e0c1f3110..3e20f8d05 100644 --- a/crates/lib-dialects/src/duckdb.rs +++ b/crates/lib-dialects/src/duckdb.rs @@ -12,13 +12,15 @@ use sqruff_lib_core::parser::parsers::StringParser; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::vec_of_erased; +use crate::{ansi, postgres}; + pub fn dialect() -> Dialect { raw_dialect().config(|dialect| dialect.expand()) } pub fn raw_dialect() -> Dialect { - let ansi_dialect = super::ansi::raw_dialect(); - let postgres_dialect = super::postgres::dialect(); + let ansi_dialect = ansi::raw_dialect(); + let postgres_dialect = postgres::dialect(); let mut duckdb_dialect = postgres_dialect; duckdb_dialect.name = DialectKind::Duckdb; @@ -60,6 +62,15 @@ pub fn raw_dialect() -> Dialect { ) .into(), ), + ( + "LoadStatementSegment".into(), + Sequence::new(vec_of_erased![ + Ref::keyword("LOAD"), + Ref::new("SingleIdentifierGrammar"), + ]) + .to_matchable() + .into(), + ), ]); duckdb_dialect.insert_lexer_matchers( @@ -177,5 +188,17 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ); + duckdb_dialect.replace_grammar( + "StatementSegment", + postgres::statement_segment().copy( + Some(vec_of_erased![Ref::new("LoadStatementSegment")]), + None, + None, + None, + vec![], + false, + ), + ); + duckdb_dialect } diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/load_statement.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/load_statement.sql new file mode 100644 index 000000000..3e666b894 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/load_statement.sql @@ -0,0 +1 @@ +LOAD spatial; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/load_statement.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/load_statement.yml new file mode 100644 index 000000000..19e9b0a46 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/load_statement.yml @@ -0,0 +1,5 @@ +file: +- statement: + - keyword: LOAD + - naked_identifier: spatial +- statement_terminator: ;