mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-22 11:41:46 +00:00
Parse byte/bit string literals in MySQL and Postgres (#1532)
This commit is contained in:
parent
73947a5f02
commit
fad2ddd641
3 changed files with 25 additions and 2 deletions
|
@ -704,8 +704,9 @@ impl<'a> Tokenizer<'a> {
|
||||||
}
|
}
|
||||||
Ok(Some(Token::Whitespace(Whitespace::Newline)))
|
Ok(Some(Token::Whitespace(Whitespace::Newline)))
|
||||||
}
|
}
|
||||||
// BigQuery uses b or B for byte string literal
|
// 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 | GenericDialect) => {
|
b @ 'B' | b @ 'b' if dialect_of!(self is BigQueryDialect | PostgreSqlDialect | MySqlDialect | GenericDialect) =>
|
||||||
|
{
|
||||||
chars.next(); // consume
|
chars.next(); // consume
|
||||||
match chars.peek() {
|
match chars.peek() {
|
||||||
Some('\'') => {
|
Some('\'') => {
|
||||||
|
|
|
@ -2960,3 +2960,14 @@ fn parse_logical_xor() {
|
||||||
select.projection[3]
|
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())
|
||||||
|
))]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -5098,3 +5098,14 @@ fn parse_create_type_as_enum() {
|
||||||
_ => unreachable!(),
|
_ => 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())
|
||||||
|
))]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue