Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dialect/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl Dialect for DuckDbDialect {
true
}

fn supports_bitwise_shift_operators(&self) -> bool {
true
}

fn supports_named_fn_args_with_eq_operator(&self) -> bool {
true
}
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ impl Dialect for GenericDialect {
true
}

fn supports_bitwise_shift_operators(&self) -> bool {
true
}

fn supports_comment_on(&self) -> bool {
true
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,11 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if the dialect supports `<<` and `>>` shift operators.
fn supports_bitwise_shift_operators(&self) -> bool {
false
}

/// Returns true if the dialect supports nested comments
/// e.g. `/* /* nested */ */`
fn supports_nested_comments(&self) -> bool {
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ impl Dialect for MySqlDialect {
true
}

fn supports_bitwise_shift_operators(&self) -> bool {
true
}

fn parse_infix(
&self,
parser: &mut crate::parser::Parser,
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ impl Dialect for PostgreSqlDialect {
true
}

fn supports_bitwise_shift_operators(&self) -> bool {
true
}

/// see <https://www.postgresql.org/docs/current/sql-comment.html>
fn supports_comment_on(&self) -> bool {
true
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/redshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ impl Dialect for RedshiftSqlDialect {
true
}

fn supports_bitwise_shift_operators(&self) -> bool {
true
}

fn supports_array_typedef_with_brackets(&self) -> bool {
true
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3485,10 +3485,10 @@ impl<'a> Parser<'a> {
Token::DuckIntDiv if dialect_is!(dialect is DuckDbDialect | GenericDialect) => {
Some(BinaryOperator::DuckIntegerDivide)
}
Token::ShiftLeft if dialect_is!(dialect is PostgreSqlDialect | DuckDbDialect | GenericDialect | RedshiftSqlDialect) => {
Token::ShiftLeft if dialect.supports_bitwise_shift_operators() => {
Some(BinaryOperator::PGBitwiseShiftLeft)
}
Token::ShiftRight if dialect_is!(dialect is PostgreSqlDialect | DuckDbDialect | GenericDialect | RedshiftSqlDialect) => {
Token::ShiftRight if dialect.supports_bitwise_shift_operators() => {
Some(BinaryOperator::PGBitwiseShiftRight)
}
Token::Sharp if dialect_is!(dialect is PostgreSqlDialect | RedshiftSqlDialect) => {
Expand Down
23 changes: 23 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,29 @@ fn parse_bitwise_ops() {
}
}

#[test]
fn parse_bitwise_shift_ops() {
let dialects = all_dialects_where(|d| d.supports_bitwise_shift_operators());
let sql = "SELECT 1 << 2, 3 >> 4";
let select = dialects.verified_only_select(sql);
assert_eq!(
SelectItem::UnnamedExpr(Expr::BinaryOp {
left: Box::new(Expr::Value((number("1")).with_empty_span())),
op: BinaryOperator::PGBitwiseShiftLeft,
right: Box::new(Expr::Value((number("2")).with_empty_span())),
}),
select.projection[0]
);
assert_eq!(
SelectItem::UnnamedExpr(Expr::BinaryOp {
left: Box::new(Expr::Value((number("3")).with_empty_span())),
op: BinaryOperator::PGBitwiseShiftRight,
right: Box::new(Expr::Value((number("4")).with_empty_span())),
}),
select.projection[1]
);
}

#[test]
fn parse_binary_any() {
let select = verified_only_select("SELECT a = ANY(b)");
Expand Down