Skip to content

Commit a3930a0

Browse files
Address UNLOGGED review comments
1 parent d85d336 commit a3930a0

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

src/parser/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,18 +5137,18 @@ impl<'a> Parser<'a> {
51375137
let temporary = self
51385138
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
51395139
.is_some();
5140-
let unlogged = dialect_of!(self is PostgreSqlDialect | GenericDialect)
5141-
&& self.parse_keyword(Keyword::UNLOGGED);
51425140
let persistent = dialect_of!(self is DuckDbDialect)
51435141
&& self.parse_one_of_keywords(&[Keyword::PERSISTENT]).is_some();
51445142
let create_view_params = self.parse_create_view_params()?;
51455143
if self.peek_keywords(&[Keyword::SNAPSHOT, Keyword::TABLE]) {
51465144
self.parse_create_snapshot_table().map(Into::into)
5145+
} else if self.peek_keywords(&[Keyword::UNLOGGED, Keyword::TABLE]) {
5146+
self.expect_keywords(&[Keyword::UNLOGGED, Keyword::TABLE])?;
5147+
self.parse_create_table(or_replace, temporary, true, global, transient)
5148+
.map(Into::into)
51475149
} else if self.parse_keyword(Keyword::TABLE) {
5148-
self.parse_create_table(or_replace, temporary, unlogged, global, transient)
5150+
self.parse_create_table(or_replace, temporary, false, global, transient)
51495151
.map(Into::into)
5150-
} else if unlogged {
5151-
self.expected_ref("TABLE after UNLOGGED", self.peek_token_ref())
51525152
} else if self.peek_keyword(Keyword::MATERIALIZED)
51535153
|| self.peek_keyword(Keyword::VIEW)
51545154
|| self.peek_keywords(&[Keyword::SECURE, Keyword::MATERIALIZED, Keyword::VIEW])
@@ -10670,13 +10670,9 @@ impl<'a> Parser<'a> {
1067010670
} else if self.parse_keywords(&[Keyword::VALIDATE, Keyword::CONSTRAINT]) {
1067110671
let name = self.parse_identifier()?;
1067210672
AlterTableOperation::ValidateConstraint { name }
10673-
} else if dialect_of!(self is PostgreSqlDialect | GenericDialect)
10674-
&& self.parse_keywords(&[Keyword::SET, Keyword::LOGGED])
10675-
{
10673+
} else if self.parse_keywords(&[Keyword::SET, Keyword::LOGGED]) {
1067610674
AlterTableOperation::SetLogged
10677-
} else if dialect_of!(self is PostgreSqlDialect | GenericDialect)
10678-
&& self.parse_keywords(&[Keyword::SET, Keyword::UNLOGGED])
10679-
{
10675+
} else if self.parse_keywords(&[Keyword::SET, Keyword::UNLOGGED]) {
1068010676
AlterTableOperation::SetUnlogged
1068110677
} else {
1068210678
let mut options =

tests/sqlparser_common.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18890,3 +18890,27 @@ fn parse_non_pg_dialects_keep_xml_names_as_regular_identifiers() {
1889018890
let dialects = all_dialects_except(|d| d.supports_xml_expressions());
1889118891
dialects.verified_only_select("SELECT xml FROM t");
1889218892
}
18893+
18894+
#[test]
18895+
fn parse_unlogged_table_logging_controls_in_all_dialects() {
18896+
match all_dialects().verified_stmt("CREATE UNLOGGED TABLE t (a INT)") {
18897+
Statement::CreateTable(CreateTable { unlogged, .. }) => {
18898+
assert!(unlogged);
18899+
}
18900+
_ => unreachable!("Expected CREATE TABLE"),
18901+
}
18902+
18903+
match all_dialects().verified_stmt("ALTER TABLE t SET LOGGED") {
18904+
Statement::AlterTable(AlterTable { operations, .. }) => {
18905+
assert_eq!(vec![AlterTableOperation::SetLogged], operations);
18906+
}
18907+
_ => unreachable!("Expected ALTER TABLE"),
18908+
}
18909+
18910+
match all_dialects().verified_stmt("ALTER TABLE t SET UNLOGGED") {
18911+
Statement::AlterTable(AlterTable { operations, .. }) => {
18912+
assert_eq!(vec![AlterTableOperation::SetUnlogged], operations);
18913+
}
18914+
_ => unreachable!("Expected ALTER TABLE"),
18915+
}
18916+
}

tests/sqlparser_postgres.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5763,11 +5763,10 @@ fn parse_create_unlogged_table() {
57635763
_ => unreachable!(),
57645764
}
57655765

5766-
// Negative test: UNLOGGED without TABLE should error
57675766
let res = pg().parse_sql_statements("CREATE UNLOGGED VIEW v AS SELECT 1");
5768-
assert!(
5769-
res.is_err(),
5770-
"CREATE UNLOGGED should only be followed by TABLE"
5767+
assert_eq!(
5768+
ParserError::ParserError("Expected: an object type after CREATE, found: UNLOGGED".into()),
5769+
res.unwrap_err()
57715770
);
57725771
}
57735772

0 commit comments

Comments
 (0)