Skip to content

Commit 27acd40

Browse files
tests: cover unlogged table and logged state operations
Add PostgreSQL regression coverage for the new syntax support and\nupdate existing struct-literal CreateTable expectations with the\nnew unlogged field in cross-dialect tests.\n\n- add parse_create_unlogged_table\n- add parse_alter_table_set_logged_unlogged\n- set unlogged defaults in duckdb/mssql fixture assertions
1 parent 5bbf9e3 commit 27acd40

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

tests/sqlparser_duckdb.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ fn test_duckdb_union_datatype() {
703703
Statement::CreateTable(CreateTable {
704704
or_replace: Default::default(),
705705
temporary: Default::default(),
706+
unlogged: Default::default(),
706707
external: Default::default(),
707708
global: Default::default(),
708709
if_not_exists: Default::default(),

tests/sqlparser_mssql.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,7 @@ fn parse_create_table_with_valid_options() {
19241924
Statement::CreateTable(CreateTable {
19251925
or_replace: false,
19261926
temporary: false,
1927+
unlogged: false,
19271928
external: false,
19281929
global: None,
19291930
dynamic: false,
@@ -2117,6 +2118,7 @@ fn parse_create_table_with_identity_column() {
21172118
Statement::CreateTable(CreateTable {
21182119
or_replace: false,
21192120
temporary: false,
2121+
unlogged: false,
21202122
external: false,
21212123
global: None,
21222124
dynamic: false,

tests/sqlparser_postgres.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,33 @@ fn parse_alter_table_owner_to() {
11921192
);
11931193
}
11941194

1195+
#[test]
1196+
fn parse_alter_table_set_logged_unlogged() {
1197+
let sql = "ALTER TABLE unlogged1 SET LOGGED";
1198+
match pg_and_generic().verified_stmt(sql) {
1199+
Statement::AlterTable(AlterTable {
1200+
name, operations, ..
1201+
}) => {
1202+
assert_eq!("unlogged1", name.to_string());
1203+
assert_eq!(vec![AlterTableOperation::SetLogged], operations);
1204+
}
1205+
_ => unreachable!(),
1206+
}
1207+
pg_and_generic().one_statement_parses_to(sql, sql);
1208+
1209+
let sql = "ALTER TABLE unlogged1 SET UNLOGGED";
1210+
match pg_and_generic().verified_stmt(sql) {
1211+
Statement::AlterTable(AlterTable {
1212+
name, operations, ..
1213+
}) => {
1214+
assert_eq!("unlogged1", name.to_string());
1215+
assert_eq!(vec![AlterTableOperation::SetUnlogged], operations);
1216+
}
1217+
_ => unreachable!(),
1218+
}
1219+
pg_and_generic().one_statement_parses_to(sql, sql);
1220+
}
1221+
11951222
#[test]
11961223
fn parse_create_table_if_not_exists() {
11971224
let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()";
@@ -5692,6 +5719,51 @@ fn parse_create_table_with_partition_by() {
56925719
}
56935720
}
56945721

5722+
#[test]
5723+
fn parse_create_unlogged_table() {
5724+
let sql = "CREATE UNLOGGED TABLE public.unlogged2 (a int primary key)";
5725+
match pg_and_generic().one_statement_parses_to(
5726+
sql,
5727+
"CREATE UNLOGGED TABLE public.unlogged2 (a INT PRIMARY KEY)",
5728+
) {
5729+
Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
5730+
assert!(unlogged);
5731+
assert_eq!("public.unlogged2", name.to_string());
5732+
}
5733+
_ => unreachable!(),
5734+
}
5735+
5736+
let sql = "CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key)";
5737+
match pg_and_generic().one_statement_parses_to(
5738+
sql,
5739+
"CREATE UNLOGGED TABLE pg_temp.unlogged3 (a INT PRIMARY KEY)",
5740+
) {
5741+
Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
5742+
assert!(unlogged);
5743+
assert_eq!("pg_temp.unlogged3", name.to_string());
5744+
}
5745+
_ => unreachable!(),
5746+
}
5747+
5748+
let sql = "CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a)";
5749+
match pg_and_generic().one_statement_parses_to(
5750+
sql,
5751+
"CREATE UNLOGGED TABLE unlogged1 (a INT) PARTITION BY RANGE(a)",
5752+
) {
5753+
Statement::CreateTable(CreateTable {
5754+
name,
5755+
unlogged,
5756+
partition_by,
5757+
..
5758+
}) => {
5759+
assert!(unlogged);
5760+
assert_eq!("unlogged1", name.to_string());
5761+
assert!(partition_by.is_some());
5762+
}
5763+
_ => unreachable!(),
5764+
}
5765+
}
5766+
56955767
#[test]
56965768
fn parse_join_constraint_unnest_alias() {
56975769
assert_eq!(
@@ -6638,6 +6710,7 @@ fn parse_trigger_related_functions() {
66386710
CreateTable {
66396711
or_replace: false,
66406712
temporary: false,
6713+
unlogged: false,
66416714
external: false,
66426715
global: None,
66436716
dynamic: false,

0 commit comments

Comments
 (0)