Skip to content

Commit cf5f8f5

Browse files
Parse ALTER COLUMN in ALTER MATERIALIZED VIEW as in ALTER VIEW
1 parent 145e5cd commit cf5f8f5

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

‎src/parser/mod.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12174,11 +12174,6 @@ impl<'a> Parser<'a> {
1217412174
old_column_name,
1217512175
new_column_name: self.parse_identifier()?,
1217612176
}
12177-
} else if materialized {
12178-
return self.expected_ref(
12179-
"OWNER TO, RENAME, SET or RESET after ALTER MATERIALIZED VIEW",
12180-
self.peek_token_ref(),
12181-
);
1218212177
} else if self.parse_keyword(Keyword::ALTER) {
1218312178
let _ = self.parse_keyword(Keyword::COLUMN);
1218412179
let column_name = self.parse_identifier()?;

‎tests/sqlparser_postgres.rs‎

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12242,27 +12242,28 @@ fn parse_alter_materialized_view() {
1224212242
] {
1224312243
pg_and_generic().verified_stmt(sql);
1224412244
}
12245+
assert_eq!(
12246+
pg_and_generic().verified_stmt("ALTER MATERIALIZED VIEW m ALTER COLUMN c SET DEFAULT 1"),
12247+
Statement::AlterView(AlterView {
12248+
materialized: true,
12249+
name: ObjectName::from(vec![Ident::new("m")]),
12250+
if_exists: false,
12251+
operation: AlterViewOperation::AlterColumn {
12252+
column_name: Ident::new("c"),
12253+
op: AlterColumnOperation::SetDefault {
12254+
value: Expr::value(number("1")),
12255+
},
12256+
},
12257+
})
12258+
);
12259+
pg_and_generic().verified_stmt("ALTER MATERIALIZED VIEW m ALTER COLUMN c DROP DEFAULT");
1224512260

12246-
for (sql, expected) in [
12247-
(
12248-
"ALTER MATERIALIZED VIEW m AS SELECT 1",
12249-
"Expected: OWNER TO, RENAME, SET or RESET after ALTER MATERIALIZED VIEW, found: AS",
12250-
),
12251-
(
12252-
"ALTER MATERIALIZED VIEW m ALTER COLUMN c SET DEFAULT 1",
12253-
"Expected: OWNER TO, RENAME, SET or RESET after ALTER MATERIALIZED VIEW, found: ALTER",
12254-
),
12255-
(
12256-
"ALTER MATERIALIZED m OWNER TO alice",
12257-
"Expected: VIEW, found: m",
12258-
),
12259-
] {
12260-
assert_eq!(
12261-
pg_and_generic().parse_sql_statements(sql).unwrap_err(),
12262-
ParserError::ParserError(expected.to_string()),
12263-
"{sql}"
12264-
);
12265-
}
12261+
assert_eq!(
12262+
pg_and_generic()
12263+
.parse_sql_statements("ALTER MATERIALIZED m OWNER TO alice")
12264+
.unwrap_err(),
12265+
ParserError::ParserError("Expected: VIEW, found: m".to_string())
12266+
);
1226612267
}
1226712268

1226812269
#[test]

0 commit comments

Comments
 (0)