You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by lu...@apache.org on 2026/09/22 23:08:17 UTC
(datafusion-sqlparser-rs) branch mssql-declare-comma-separator created (now b1e2bbde3)
This is an automated email from the ASF dual-hosted git repository.
LucaCappelletti94 pushed a change to branch mssql-declare-comma-separator
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
at b1e2bbde3 MsSql: Keep the comma separator when displaying DECLARE lists
This branch includes the following new commits:
new b1e2bbde3 MsSql: Keep the comma separator when displaying DECLARE lists
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion-sqlparser-rs) 01/01: MsSql: Keep the comma separator when displaying DECLARE lists
Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
LucaCappelletti94 pushed a commit to branch mssql-declare-comma-separator
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit b1e2bbde3d9d6f8c34e46e3a00e2fefe3e6d6da9
Author: LucaCappelletti94 <ca...@gmail.com>
AuthorDate: Wed Sep 23 01:08:06 2026 +0200
MsSql: Keep the comma separator when displaying DECLARE lists
---
src/ast/mod.rs | 23 ++++++++++++++++++++---
src/parser/mod.rs | 12 ++++++++++--
tests/sqlparser_bigquery.rs | 2 +-
tests/sqlparser_mssql.rs | 13 +++++++++++--
tests/sqlparser_snowflake.rs | 10 +++++-----
5 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index dcde4fc38..2e826049a 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -3125,6 +3125,18 @@ impl fmt::Display for DeclareType {
}
}
+/// Separator written between the declarations collected by one `DECLARE` keyword.
+#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub enum DeclareSeparator {
+ /// One declaration per line of a Snowflake Scripting `DECLARE` section.
+ #[default]
+ Semicolon,
+ /// One comma-separated list, the MsSql form `DECLARE @a INT, @b INT`.
+ Comma,
+}
+
/// A `DECLARE` statement.
/// [PostgreSQL] [Snowflake] [BigQuery]
///
@@ -4065,6 +4077,8 @@ pub enum Statement {
Declare {
/// Cursor declaration statements collected by `DECLARE`.
stmts: Vec<Declare>,
+ /// Separator between `stmts` in the rendered SQL.
+ separator: DeclareSeparator,
},
/// ```sql
/// CREATE EXTENSION [ IF NOT EXISTS ] extension_name
@@ -5242,9 +5256,12 @@ impl fmt::Display for Statement {
write!(f, "{statement}")
}
Statement::Query(s) => s.fmt(f),
- Statement::Declare { stmts } => {
- write!(f, "DECLARE ")?;
- write!(f, "{}", display_separated(stmts, "; "))
+ Statement::Declare { stmts, separator } => {
+ let sep = match separator {
+ DeclareSeparator::Comma => ", ",
+ DeclareSeparator::Semicolon => "; ",
+ };
+ write!(f, "DECLARE {}", display_separated(stmts, sep))
}
Statement::Fetch {
name,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index eb435f153..12491723f 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -7901,6 +7901,7 @@ impl<'a> Parser<'a> {
hold,
for_query: query,
}],
+ separator: DeclareSeparator::Semicolon,
})
}
@@ -7944,6 +7945,7 @@ impl<'a> Parser<'a> {
hold: None,
for_query: None,
}],
+ separator: DeclareSeparator::Semicolon,
})
}
@@ -8060,7 +8062,10 @@ impl<'a> Parser<'a> {
break;
}
- Ok(Statement::Declare { stmts })
+ Ok(Statement::Declare {
+ stmts,
+ separator: DeclareSeparator::Semicolon,
+ })
}
/// Parse a [MsSql] `DECLARE` statement.
@@ -8077,7 +8082,10 @@ impl<'a> Parser<'a> {
pub fn parse_mssql_declare(&mut self) -> Result<Statement, ParserError> {
let stmts = self.parse_comma_separated(Parser::parse_mssql_declare_stmt)?;
- Ok(Statement::Declare { stmts })
+ Ok(Statement::Declare {
+ stmts,
+ separator: DeclareSeparator::Comma,
+ })
}
/// Parse the body of a [MsSql] `DECLARE`statement.
diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs
index d6ae192e4..d4a9dbedc 100644
--- a/tests/sqlparser_bigquery.rs
+++ b/tests/sqlparser_bigquery.rs
@@ -2174,7 +2174,7 @@ fn parse_big_query_declare() {
),
] {
match bigquery().verified_stmt(sql) {
- Statement::Declare { mut stmts } => {
+ Statement::Declare { mut stmts, .. } => {
assert_eq!(1, stmts.len());
let Declare {
names,
diff --git a/tests/sqlparser_mssql.rs b/tests/sqlparser_mssql.rs
index 4510f953e..dcb024f10 100644
--- a/tests/sqlparser_mssql.rs
+++ b/tests/sqlparser_mssql.rs
@@ -1467,7 +1467,8 @@ fn parse_mssql_declare() {
hold: None,
for_query: None
}
- ]
+ ],
+ separator: DeclareSeparator::Comma,
}],
ast
);
@@ -1487,7 +1488,8 @@ fn parse_mssql_declare() {
scroll: None,
hold: None,
for_query: None
- }]
+ }],
+ separator: DeclareSeparator::Comma,
},
Statement::Set(Set::SingleAssignment {
scope: None,
@@ -2941,3 +2943,10 @@ fn parse_bracket_quoted_function_argument_name() {
}])
);
}
+
+#[test]
+fn parse_mssql_declare_comma_list_display() {
+ ms().verified_stmt("DECLARE @a INT, @b INT");
+ ms().verified_stmt("DECLARE @a INT = 1, @b TEXT = 'x'");
+ ms().verified_stmt("DECLARE @foo CURSOR, @bar INT");
+}
diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs
index 37222341b..85e376145 100644
--- a/tests/sqlparser_snowflake.rs
+++ b/tests/sqlparser_snowflake.rs
@@ -1736,7 +1736,7 @@ fn parse_snowflake_declare_cursor() {
),
] {
match snowflake().verified_stmt(sql) {
- Statement::Declare { mut stmts } => {
+ Statement::Declare { mut stmts, .. } => {
assert_eq!(1, stmts.len());
let Declare {
names,
@@ -1804,7 +1804,7 @@ fn parse_snowflake_declare_result_set() {
("DECLARE res RESULTSET", "res", None),
] {
match snowflake().verified_stmt(sql) {
- Statement::Declare { mut stmts } => {
+ Statement::Declare { mut stmts, .. } => {
assert_eq!(1, stmts.len());
let Declare {
names,
@@ -1857,7 +1857,7 @@ fn parse_snowflake_declare_exception() {
("DECLARE ex EXCEPTION", "ex", None),
] {
match snowflake().verified_stmt(sql) {
- Statement::Declare { mut stmts } => {
+ Statement::Declare { mut stmts, .. } => {
assert_eq!(1, stmts.len());
let Declare {
names,
@@ -1897,7 +1897,7 @@ fn parse_snowflake_declare_variable() {
("DECLARE profit", "profit", None, None),
] {
match snowflake().verified_stmt(sql) {
- Statement::Declare { mut stmts } => {
+ Statement::Declare { mut stmts, .. } => {
assert_eq!(1, stmts.len());
let Declare {
names,
@@ -1947,7 +1947,7 @@ fn parse_snowflake_declare_multi_statements() {
"ex EXCEPTION (-20003, 'ERROR: Could not create table.')"
);
match snowflake().verified_stmt(sql) {
- Statement::Declare { stmts } => {
+ Statement::Declare { stmts, .. } => {
let actual = stmts
.iter()
.map(|stmt| (stmt.names[0].value.as_str(), stmt.declare_type.clone()))
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org