Skip to content

Commit e71f9cf

Browse files
committed
allow listen/notify syntax for postgres, deny for others
1 parent d526a64 commit e71f9cf

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

src/ast/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3283,14 +3283,14 @@ pub enum Statement {
32833283
/// ```
32843284
/// listen for a notification channel
32853285
///
3286-
/// See Postgres <https://www.postgresql.org/docs/current/sql-notify.html>
3286+
/// See Postgres <https://www.postgresql.org/docs/current/sql-listen.html>
32873287
LISTEN { channel: Ident },
32883288
/// ```sql
32893289
/// NOTIFY channel [ , payload ]
32903290
/// ```
32913291
/// send a notification event together with an optional “payload” string to channel
32923292
///
3293-
/// See Postgres <https://www.postgresql.org/docs/current/sql-listen.html>
3293+
/// See Postgres <https://www.postgresql.org/docs/current/sql-notify.html>
32943294
NOTIFY {
32953295
channel: Ident,
32963296
payload: Option<String>,

src/parser/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ impl<'a> Parser<'a> {
534534
Keyword::MERGE => self.parse_merge(),
535535
// `LISTEN` and `NOTIFY` are Postgres-specific
536536
// syntaxes. They are used for Postgres statement.
537-
Keyword::LISTEN => self.parse_listen(),
538-
Keyword::NOTIFY => self.parse_notify(),
537+
Keyword::LISTEN if dialect_of!(self is PostgreSqlDialect | GenericDialect) => self.parse_listen(),
538+
Keyword::NOTIFY if dialect_of!(self is PostgreSqlDialect | GenericDialect) => self.parse_notify(),
539539
// `PRAGMA` is sqlite specific https://www.sqlite.org/pragma.html
540540
Keyword::PRAGMA => self.parse_pragma(),
541541
Keyword::UNLOAD => self.parse_unload(),

tests/sqlparser_common.rs

-31
Original file line numberDiff line numberDiff line change
@@ -11460,34 +11460,3 @@ fn test_try_convert() {
1146011460
all_dialects_where(|d| d.supports_try_convert() && !d.convert_type_before_value());
1146111461
dialects.verified_expr("TRY_CONVERT('foo', VARCHAR(MAX))");
1146211462
}
11463-
11464-
#[test]
11465-
fn test_listen() {
11466-
match verified_stmt("LISTEN test1") {
11467-
Statement::LISTEN { channel } => {
11468-
assert_eq!(Ident::new("test1"), channel);
11469-
}
11470-
_ => unreachable!(),
11471-
}
11472-
}
11473-
11474-
#[test]
11475-
fn test_notify() {
11476-
match verified_stmt("NOTIFY test1") {
11477-
Statement::NOTIFY { channel, payload } => {
11478-
assert_eq!(Ident::new("test1"), channel);
11479-
assert_eq!(payload, None);
11480-
}
11481-
_ => unreachable!(),
11482-
}
11483-
match verified_stmt("NOTIFY test1, 'this is a test notification'") {
11484-
Statement::NOTIFY {
11485-
channel,
11486-
payload: Some(payload),
11487-
} => {
11488-
assert_eq!(Ident::new("test1"), channel);
11489-
assert_eq!("this is a test notification", payload);
11490-
}
11491-
_ => unreachable!(),
11492-
}
11493-
}

tests/sqlparser_postgres.rs

+31
Original file line numberDiff line numberDiff line change
@@ -5157,3 +5157,34 @@ fn parse_create_type_as_enum() {
51575157
_ => unreachable!(),
51585158
}
51595159
}
5160+
5161+
#[test]
5162+
fn parse_listen_channel() {
5163+
match pg_and_generic().verified_stmt("LISTEN test1") {
5164+
Statement::LISTEN { channel } => {
5165+
assert_eq!(Ident::new("test1"), channel);
5166+
}
5167+
_ => unreachable!(),
5168+
}
5169+
}
5170+
5171+
#[test]
5172+
fn parse_notify_channel() {
5173+
match pg_and_generic().verified_stmt("NOTIFY test1") {
5174+
Statement::NOTIFY { channel, payload } => {
5175+
assert_eq!(Ident::new("test1"), channel);
5176+
assert_eq!(payload, None);
5177+
}
5178+
_ => unreachable!(),
5179+
}
5180+
match pg_and_generic().verified_stmt("NOTIFY test1, 'this is a test notification'") {
5181+
Statement::NOTIFY {
5182+
channel,
5183+
payload: Some(payload),
5184+
} => {
5185+
assert_eq!(Ident::new("test1"), channel);
5186+
assert_eq!("this is a test notification", payload);
5187+
}
5188+
_ => unreachable!(),
5189+
}
5190+
}

0 commit comments

Comments
 (0)