mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Add support for PostgreSQL UNLISTEN syntax and Add support for Postgres LOAD extension expr (#1531)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
92be237cfc
commit
73947a5f02
7 changed files with 113 additions and 33 deletions
|
|
@ -11595,7 +11595,7 @@ fn test_show_dbs_schemas_tables_views() {
|
|||
|
||||
#[test]
|
||||
fn parse_listen_channel() {
|
||||
let dialects = all_dialects_where(|d| d.supports_listen());
|
||||
let dialects = all_dialects_where(|d| d.supports_listen_notify());
|
||||
|
||||
match dialects.verified_stmt("LISTEN test1") {
|
||||
Statement::LISTEN { channel } => {
|
||||
|
|
@ -11609,7 +11609,7 @@ fn parse_listen_channel() {
|
|||
ParserError::ParserError("Expected: identifier, found: *".to_string())
|
||||
);
|
||||
|
||||
let dialects = all_dialects_where(|d| !d.supports_listen());
|
||||
let dialects = all_dialects_where(|d| !d.supports_listen_notify());
|
||||
|
||||
assert_eq!(
|
||||
dialects.parse_sql_statements("LISTEN test1").unwrap_err(),
|
||||
|
|
@ -11617,9 +11617,40 @@ fn parse_listen_channel() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_unlisten_channel() {
|
||||
let dialects = all_dialects_where(|d| d.supports_listen_notify());
|
||||
|
||||
match dialects.verified_stmt("UNLISTEN test1") {
|
||||
Statement::UNLISTEN { channel } => {
|
||||
assert_eq!(Ident::new("test1"), channel);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match dialects.verified_stmt("UNLISTEN *") {
|
||||
Statement::UNLISTEN { channel } => {
|
||||
assert_eq!(Ident::new("*"), channel);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
dialects.parse_sql_statements("UNLISTEN +").unwrap_err(),
|
||||
ParserError::ParserError("Expected: wildcard or identifier, found: +".to_string())
|
||||
);
|
||||
|
||||
let dialects = all_dialects_where(|d| !d.supports_listen_notify());
|
||||
|
||||
assert_eq!(
|
||||
dialects.parse_sql_statements("UNLISTEN test1").unwrap_err(),
|
||||
ParserError::ParserError("Expected: an SQL statement, found: UNLISTEN".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_notify_channel() {
|
||||
let dialects = all_dialects_where(|d| d.supports_notify());
|
||||
let dialects = all_dialects_where(|d| d.supports_listen_notify());
|
||||
|
||||
match dialects.verified_stmt("NOTIFY test1") {
|
||||
Statement::NOTIFY { channel, payload } => {
|
||||
|
|
@ -11655,7 +11686,7 @@ fn parse_notify_channel() {
|
|||
"NOTIFY test1",
|
||||
"NOTIFY test1, 'this is a test notification'",
|
||||
];
|
||||
let dialects = all_dialects_where(|d| !d.supports_notify());
|
||||
let dialects = all_dialects_where(|d| !d.supports_listen_notify());
|
||||
|
||||
for &sql in &sql_statements {
|
||||
assert_eq!(
|
||||
|
|
@ -11864,6 +11895,44 @@ fn parse_load_data() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_load_extension() {
|
||||
let dialects = all_dialects_where(|d| d.supports_load_extension());
|
||||
let not_supports_load_extension_dialects = all_dialects_where(|d| !d.supports_load_extension());
|
||||
let sql = "LOAD my_extension";
|
||||
|
||||
match dialects.verified_stmt(sql) {
|
||||
Statement::Load { extension_name } => {
|
||||
assert_eq!(Ident::new("my_extension"), extension_name);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
not_supports_load_extension_dialects
|
||||
.parse_sql_statements(sql)
|
||||
.unwrap_err(),
|
||||
ParserError::ParserError(
|
||||
"Expected: `DATA` or an extension name after `LOAD`, found: my_extension".to_string()
|
||||
)
|
||||
);
|
||||
|
||||
let sql = "LOAD 'filename'";
|
||||
|
||||
match dialects.verified_stmt(sql) {
|
||||
Statement::Load { extension_name } => {
|
||||
assert_eq!(
|
||||
Ident {
|
||||
value: "filename".to_string(),
|
||||
quote_style: Some('\'')
|
||||
},
|
||||
extension_name
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_select_top() {
|
||||
let dialects = all_dialects_where(|d| d.supports_top_before_distinct());
|
||||
|
|
|
|||
|
|
@ -359,20 +359,6 @@ fn test_duckdb_install() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duckdb_load_extension() {
|
||||
let stmt = duckdb().verified_stmt("LOAD my_extension");
|
||||
assert_eq!(
|
||||
Statement::Load {
|
||||
extension_name: Ident {
|
||||
value: "my_extension".to_string(),
|
||||
quote_style: None
|
||||
}
|
||||
},
|
||||
stmt
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duckdb_struct_literal() {
|
||||
//struct literal syntax https://duckdb.org/docs/sql/data_types/struct#creating-structs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue