This is an automated email from the ASF dual-hosted git repository.
iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new fad2ddd6 Parse byte/bit string literals in MySQL and Postgres (#1532)
fad2ddd6 is described below
commit fad2ddd6417e2e4d149c298d1977088124a30358
Author: Michael Victor Zink <[email protected]>
AuthorDate: Tue Nov 19 21:55:38 2024 -0800
Parse byte/bit string literals in MySQL and Postgres (#1532)
---
src/tokenizer.rs | 5 +++--
tests/sqlparser_mysql.rs | 11 +++++++++++
tests/sqlparser_postgres.rs | 11 +++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 4186ec82..05aaf1e2 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -704,8 +704,9 @@ impl<'a> Tokenizer<'a> {
}
Ok(Some(Token::Whitespace(Whitespace::Newline)))
}
- // BigQuery uses b or B for byte string literal
- b @ 'B' | b @ 'b' if dialect_of!(self is BigQueryDialect |
GenericDialect) => {
+ // BigQuery and MySQL use b or B for byte string literal,
Postgres for bit strings
+ b @ 'B' | b @ 'b' if dialect_of!(self is BigQueryDialect |
PostgreSqlDialect | MySqlDialect | GenericDialect) =>
+ {
chars.next(); // consume
match chars.peek() {
Some('\'') => {
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs
index 2a876cff..ce329673 100644
--- a/tests/sqlparser_mysql.rs
+++ b/tests/sqlparser_mysql.rs
@@ -2960,3 +2960,14 @@ fn parse_logical_xor() {
select.projection[3]
);
}
+
+#[test]
+fn parse_bitstring_literal() {
+ let select = mysql_and_generic().verified_only_select("SELECT B'111'");
+ assert_eq!(
+ select.projection,
+ vec![SelectItem::UnnamedExpr(Expr::Value(
+ Value::SingleQuotedByteStringLiteral("111".to_string())
+ ))]
+ );
+}
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index a6c480cd..2e2c4403 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -5098,3 +5098,14 @@ fn parse_create_type_as_enum() {
_ => unreachable!(),
}
}
+
+#[test]
+fn parse_bitstring_literal() {
+ let select = pg_and_generic().verified_only_select("SELECT B'111'");
+ assert_eq!(
+ select.projection,
+ vec![SelectItem::UnnamedExpr(Expr::Value(
+ Value::SingleQuotedByteStringLiteral("111".to_string())
+ ))]
+ );
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]