From 9ed17c0507039fcf097b4ad0595c0b0d4c0c5e43 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 11 Nov 2026 22:40:07 +0100 Subject: [PATCH 1/4] Fix quoted placeholder roundtrips --- src/parser/mod.rs | 4 ++-- tests/sqlparser_common.rs | 35 +++-------------------------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f6f0a6cd74..5bdc75c877 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -13391,11 +13391,11 @@ impl<'a> Parser<'a> { // without any whitespace in between let next_token = self.next_token_no_skip().unwrap_or(&EOF_TOKEN).clone(); let ident = match next_token.token { - Token::Word(w) if w.quote_style.is_none() => Ok(w.into_ident(next_token.span)), + Token::Word(w) => Ok(w.into_ident(next_token.span)), Token::Number(w, false) => Ok(Ident::with_span(next_token.span, w)), _ => self.expected("placeholder", next_token), }?; - Ok(Value::Placeholder(format!("{tok}{}", ident.value)) + Ok(Value::Placeholder(format!("{tok}{ident}")) .with_span(Span::new(span.start, ident.span.end))) } unexpected => self.expected( diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index cf1547f1b0..65760f1080 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -21938,45 +21938,16 @@ fn parse_compound_field_access_numeric_display() { } #[test] -fn parse_placeholder_disallows_quoted_ident() { +fn parse_quoted_placeholders_roundtrip() { let dialects = TestedDialects::new(vec![ Box::new(AnsiDialect {}), Box::new(GenericDialect {}), Box::new(SnowflakeDialect {}), Box::new(SQLiteDialect {}), ]); - // Valid placeholders roundtrip - dialects.verified_stmt("SELECT :x"); - - // Quoted identifiers are not valid placeholders - let err = dialects.parse_sql_statements("SELECT :`a`").unwrap_err(); - assert_eq!( - ParserError::ParserError("Expected: placeholder, found: `a`".to_string()), - err - ); - let err = dialects.parse_sql_statements("SELECT :\"a\"").unwrap_err(); - assert_eq!( - ParserError::ParserError("Expected: placeholder, found: \"a\"".to_string()), - err - ); - let err = dialects.parse_sql_statements("SELECT:` a` a").unwrap_err(); - assert_eq!( - ParserError::ParserError("Expected: placeholder, found: ` a`".to_string()), - err - ); - + dialects.verified_stmt("SELECT :\"a b c\", :\"a\"\"b\""); let ansi = TestedDialects::new(vec![Box::new(AnsiDialect {})]); - ansi.verified_stmt("SELECT @x"); - let err = ansi.parse_sql_statements("SELECT @`a`").unwrap_err(); - assert_eq!( - ParserError::ParserError("Expected: placeholder, found: `a`".to_string()), - err - ); - let err = ansi.parse_sql_statements("SELECT @\"a\"").unwrap_err(); - assert_eq!( - ParserError::ParserError("Expected: placeholder, found: \"a\"".to_string()), - err - ); + ansi.verified_stmt("SELECT @\"a b c\""); } #[test] From e4cd7bc4186fd4e3da85cc0540780034aacd61e2 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 11 Nov 2026 22:43:00 +0100 Subject: [PATCH 2/4] Retain placeholder regression cases --- tests/sqlparser_common.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 65760f1080..61be465b88 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -21945,9 +21945,24 @@ fn parse_quoted_placeholders_roundtrip() { Box::new(SnowflakeDialect {}), Box::new(SQLiteDialect {}), ]); - dialects.verified_stmt("SELECT :\"a b c\", :\"a\"\"b\""); + for sql in [ + "SELECT :x", + "SELECT :`a`", + "SELECT :\"a\"", + "SELECT :` a` AS a", + "SELECT :\"a b c\", :\"a\"\"b\"", + ] { + dialects.verified_stmt(sql); + } let ansi = TestedDialects::new(vec![Box::new(AnsiDialect {})]); - ansi.verified_stmt("SELECT @\"a b c\""); + for sql in [ + "SELECT @x", + "SELECT @`a`", + "SELECT @\"a\"", + "SELECT @\"a b c\"", + ] { + ansi.verified_stmt(sql); + } } #[test] From 6ccd3697c1887a15eff293006dd05585494d3696 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 11 Nov 2026 22:44:37 +0100 Subject: [PATCH 3/4] Use raw strings for quoted placeholder tests --- tests/sqlparser_common.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 61be465b88..782d2909a9 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -21948,9 +21948,9 @@ fn parse_quoted_placeholders_roundtrip() { for sql in [ "SELECT :x", "SELECT :`a`", - "SELECT :\"a\"", + r#"SELECT :"a""#, "SELECT :` a` AS a", - "SELECT :\"a b c\", :\"a\"\"b\"", + r#"SELECT :"a b c", :"a""b""#, ] { dialects.verified_stmt(sql); } @@ -21958,8 +21958,8 @@ fn parse_quoted_placeholders_roundtrip() { for sql in [ "SELECT @x", "SELECT @`a`", - "SELECT @\"a\"", - "SELECT @\"a b c\"", + r#"SELECT @"a""#, + r#"SELECT @"a b c""#, ] { ansi.verified_stmt(sql); } From 55f5309ad150b311ea95d53df2dd869f42dc5bf4 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 11 Nov 2026 22:58:45 +0100 Subject: [PATCH 4/4] Assert parsed quoted placeholder expression --- tests/sqlparser_common.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 782d2909a9..ed98144968 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -21954,6 +21954,11 @@ fn parse_quoted_placeholders_roundtrip() { ] { dialects.verified_stmt(sql); } + let select = dialects.verified_only_select(r#"SELECT :"a b c""#); + assert_eq!( + expr_from_projection(only(&select.projection)), + &Expr::value(Value::Placeholder(r#":"a b c""#.to_string())) + ); let ansi = TestedDialects::new(vec![Box::new(AnsiDialect {})]); for sql in [ "SELECT @x",