Skip to content

Commit 1233fc1

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 fe92bd9 commit 1233fc1

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

tests/sqlparser_duckdb.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ fn test_duckdb_union_datatype() {
699699
Statement::CreateTable(CreateTable {
700700
or_replace: Default::default(),
701701
temporary: Default::default(),
702+
unlogged: Default::default(),
702703
external: Default::default(),
703704
global: Default::default(),
704705
if_not_exists: Default::default(),

tests/sqlparser_mssql.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,7 @@ fn parse_create_table_with_valid_options() {
19231923
Statement::CreateTable(CreateTable {
19241924
or_replace: false,
19251925
temporary: false,
1926+
unlogged: false,
19261927
external: false,
19271928
global: None,
19281929
dynamic: false,
@@ -2110,6 +2111,7 @@ fn parse_create_table_with_identity_column() {
21102111
Statement::CreateTable(CreateTable {
21112112
or_replace: false,
21122113
temporary: false,
2114+
unlogged: false,
21132115
external: false,
21142116
global: None,
21152117
dynamic: false,

tests/sqlparser_postgres.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,33 @@ fn parse_alter_table_owner_to() {
988988
);
989989
}
990990

991+
#[test]
992+
fn parse_alter_table_set_logged_unlogged() {
993+
let sql = "ALTER TABLE unlogged1 SET LOGGED";
994+
match pg_and_generic().verified_stmt(sql) {
995+
Statement::AlterTable(AlterTable {
996+
name, operations, ..
997+
}) => {
998+
assert_eq!("unlogged1", name.to_string());
999+
assert_eq!(vec![AlterTableOperation::SetLogged], operations);
1000+
}
1001+
_ => unreachable!(),
1002+
}
1003+
pg_and_generic().one_statement_parses_to(sql, sql);
1004+
1005+
let sql = "ALTER TABLE unlogged1 SET UNLOGGED";
1006+
match pg_and_generic().verified_stmt(sql) {
1007+
Statement::AlterTable(AlterTable {
1008+
name, operations, ..
1009+
}) => {
1010+
assert_eq!("unlogged1", name.to_string());
1011+
assert_eq!(vec![AlterTableOperation::SetUnlogged], operations);
1012+
}
1013+
_ => unreachable!(),
1014+
}
1015+
pg_and_generic().one_statement_parses_to(sql, sql);
1016+
}
1017+
9911018
#[test]
9921019
fn parse_create_table_if_not_exists() {
9931020
let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()";
@@ -5389,6 +5416,51 @@ fn parse_create_table_with_partition_by() {
53895416
}
53905417
}
53915418

5419+
#[test]
5420+
fn parse_create_unlogged_table() {
5421+
let sql = "CREATE UNLOGGED TABLE public.unlogged2 (a int primary key)";
5422+
match pg_and_generic().one_statement_parses_to(
5423+
sql,
5424+
"CREATE UNLOGGED TABLE public.unlogged2 (a INT PRIMARY KEY)",
5425+
) {
5426+
Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
5427+
assert!(unlogged);
5428+
assert_eq!("public.unlogged2", name.to_string());
5429+
}
5430+
_ => unreachable!(),
5431+
}
5432+
5433+
let sql = "CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key)";
5434+
match pg_and_generic().one_statement_parses_to(
5435+
sql,
5436+
"CREATE UNLOGGED TABLE pg_temp.unlogged3 (a INT PRIMARY KEY)",
5437+
) {
5438+
Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
5439+
assert!(unlogged);
5440+
assert_eq!("pg_temp.unlogged3", name.to_string());
5441+
}
5442+
_ => unreachable!(),
5443+
}
5444+
5445+
let sql = "CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a)";
5446+
match pg_and_generic().one_statement_parses_to(
5447+
sql,
5448+
"CREATE UNLOGGED TABLE unlogged1 (a INT) PARTITION BY RANGE(a)",
5449+
) {
5450+
Statement::CreateTable(CreateTable {
5451+
name,
5452+
unlogged,
5453+
partition_by,
5454+
..
5455+
}) => {
5456+
assert!(unlogged);
5457+
assert_eq!("unlogged1", name.to_string());
5458+
assert!(partition_by.is_some());
5459+
}
5460+
_ => unreachable!(),
5461+
}
5462+
}
5463+
53925464
#[test]
53935465
fn parse_join_constraint_unnest_alias() {
53945466
assert_eq!(
@@ -6304,6 +6376,7 @@ fn parse_trigger_related_functions() {
63046376
CreateTable {
63056377
or_replace: false,
63066378
temporary: false,
6379+
unlogged: false,
63076380
external: false,
63086381
global: None,
63096382
dynamic: false,

0 commit comments

Comments
 (0)