Skip to content

Commit 2a6609b

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 6c0e437 commit 2a6609b

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
@@ -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
@@ -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,
@@ -2116,6 +2117,7 @@ fn parse_create_table_with_identity_column() {
21162117
Statement::CreateTable(CreateTable {
21172118
or_replace: false,
21182119
temporary: false,
2120+
unlogged: false,
21192121
external: false,
21202122
global: None,
21212123
dynamic: false,

tests/sqlparser_postgres.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,33 @@ fn parse_alter_table_owner_to() {
10271027
);
10281028
}
10291029

1030+
#[test]
1031+
fn parse_alter_table_set_logged_unlogged() {
1032+
let sql = "ALTER TABLE unlogged1 SET LOGGED";
1033+
match pg_and_generic().verified_stmt(sql) {
1034+
Statement::AlterTable(AlterTable {
1035+
name, operations, ..
1036+
}) => {
1037+
assert_eq!("unlogged1", name.to_string());
1038+
assert_eq!(vec![AlterTableOperation::SetLogged], operations);
1039+
}
1040+
_ => unreachable!(),
1041+
}
1042+
pg_and_generic().one_statement_parses_to(sql, sql);
1043+
1044+
let sql = "ALTER TABLE unlogged1 SET UNLOGGED";
1045+
match pg_and_generic().verified_stmt(sql) {
1046+
Statement::AlterTable(AlterTable {
1047+
name, operations, ..
1048+
}) => {
1049+
assert_eq!("unlogged1", name.to_string());
1050+
assert_eq!(vec![AlterTableOperation::SetUnlogged], operations);
1051+
}
1052+
_ => unreachable!(),
1053+
}
1054+
pg_and_generic().one_statement_parses_to(sql, sql);
1055+
}
1056+
10301057
#[test]
10311058
fn parse_create_table_if_not_exists() {
10321059
let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()";
@@ -5508,6 +5535,51 @@ fn parse_create_table_with_partition_by() {
55085535
}
55095536
}
55105537

5538+
#[test]
5539+
fn parse_create_unlogged_table() {
5540+
let sql = "CREATE UNLOGGED TABLE public.unlogged2 (a int primary key)";
5541+
match pg_and_generic().one_statement_parses_to(
5542+
sql,
5543+
"CREATE UNLOGGED TABLE public.unlogged2 (a INT PRIMARY KEY)",
5544+
) {
5545+
Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
5546+
assert!(unlogged);
5547+
assert_eq!("public.unlogged2", name.to_string());
5548+
}
5549+
_ => unreachable!(),
5550+
}
5551+
5552+
let sql = "CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key)";
5553+
match pg_and_generic().one_statement_parses_to(
5554+
sql,
5555+
"CREATE UNLOGGED TABLE pg_temp.unlogged3 (a INT PRIMARY KEY)",
5556+
) {
5557+
Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
5558+
assert!(unlogged);
5559+
assert_eq!("pg_temp.unlogged3", name.to_string());
5560+
}
5561+
_ => unreachable!(),
5562+
}
5563+
5564+
let sql = "CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a)";
5565+
match pg_and_generic().one_statement_parses_to(
5566+
sql,
5567+
"CREATE UNLOGGED TABLE unlogged1 (a INT) PARTITION BY RANGE(a)",
5568+
) {
5569+
Statement::CreateTable(CreateTable {
5570+
name,
5571+
unlogged,
5572+
partition_by,
5573+
..
5574+
}) => {
5575+
assert!(unlogged);
5576+
assert_eq!("unlogged1", name.to_string());
5577+
assert!(partition_by.is_some());
5578+
}
5579+
_ => unreachable!(),
5580+
}
5581+
}
5582+
55115583
#[test]
55125584
fn parse_join_constraint_unnest_alias() {
55135585
assert_eq!(
@@ -6426,6 +6498,7 @@ fn parse_trigger_related_functions() {
64266498
CreateTable {
64276499
or_replace: false,
64286500
temporary: false,
6501+
unlogged: false,
64296502
external: false,
64306503
global: None,
64316504
dynamic: false,

0 commit comments

Comments
 (0)