Skip to content

Commit 3ba4c54

Browse files
Reject ON CLUSTER and LOCATION in ALTER FOREIGN TABLE
1 parent 5d446bb commit 3ba4c54

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/parser/mod.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12049,9 +12049,18 @@ impl<'a> Parser<'a> {
1204912049
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
1205012050
let only = self.parse_keyword(Keyword::ONLY); // [ ONLY ]
1205112051
let table_name = self.parse_object_name(false)?;
12052+
let on_cluster_loc = self.peek_token_ref().span.start;
1205212053
let on_cluster = self.parse_optional_on_cluster()?;
12054+
let foreign = table_type == Some(AlterTableType::Foreign);
12055+
if foreign && on_cluster.is_some() {
12056+
return parser_err!(
12057+
"Cannot specify ON CLUSTER in ALTER FOREIGN TABLE",
12058+
on_cluster_loc
12059+
);
12060+
}
1205312061
let operations = self.parse_comma_separated(Parser::parse_alter_table_operation)?;
1205412062

12063+
let location_loc = self.peek_token_ref().span.start;
1205512064
let mut location = None;
1205612065
if self.parse_keyword(Keyword::LOCATION) {
1205712066
location = Some(HiveSetLocation {
@@ -12064,6 +12073,12 @@ impl<'a> Parser<'a> {
1206412073
location: self.parse_identifier()?,
1206512074
});
1206612075
}
12076+
if foreign && location.is_some() {
12077+
return parser_err!(
12078+
"Cannot specify LOCATION in ALTER FOREIGN TABLE",
12079+
location_loc
12080+
);
12081+
}
1206712082

1206812083
let end_token = if self.peek_token_ref().token == Token::SemiColon {
1206912084
self.peek_token_ref().clone()

‎tests/sqlparser_postgres.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11537,3 +11537,30 @@ fn parse_create_foreign_table_options_errors() {
1153711537
);
1153811538
}
1153911539
}
11540+
11541+
#[test]
11542+
fn parse_alter_foreign_table_rejects_clauses() {
11543+
for (sql, expected) in [
11544+
(
11545+
"ALTER FOREIGN TABLE ft ON CLUSTER c ADD COLUMN x INT",
11546+
"Cannot specify ON CLUSTER in ALTER FOREIGN TABLE",
11547+
),
11548+
(
11549+
"ALTER FOREIGN TABLE ft ADD COLUMN x INT LOCATION 's3://x'",
11550+
"Cannot specify LOCATION in ALTER FOREIGN TABLE",
11551+
),
11552+
(
11553+
"ALTER FOREIGN TABLE ft ADD COLUMN x INT SET LOCATION 's3://x'",
11554+
"Cannot specify LOCATION in ALTER FOREIGN TABLE",
11555+
),
11556+
] {
11557+
assert_eq!(
11558+
pg_and_generic()
11559+
.parse_sql_statements(sql)
11560+
.unwrap_err()
11561+
.to_string(),
11562+
format!("sql parser error: {expected}"),
11563+
"{sql}"
11564+
);
11565+
}
11566+
}

0 commit comments

Comments
 (0)