Add support for INHERITS option in CREATE TABLE statement (#1806)

This commit is contained in:
Luca Cappelletti 2025-04-12 18:03:43 +02:00 committed by GitHub
parent bbc80d7537
commit 896c088153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 71 additions and 2 deletions

View file

@ -2733,6 +2733,41 @@ fn parse_create_brin() {
}
}
#[test]
fn parse_create_table_with_inherits() {
let single_inheritance_sql =
"CREATE TABLE child_table (child_column INT) INHERITS (public.parent_table)";
match pg().verified_stmt(single_inheritance_sql) {
Statement::CreateTable(CreateTable {
inherits: Some(inherits),
..
}) => {
assert_eq_vec(&["public", "parent_table"], &inherits[0].0);
}
_ => unreachable!(),
}
let double_inheritance_sql = "CREATE TABLE child_table (child_column INT) INHERITS (public.parent_table, pg_catalog.pg_settings)";
match pg().verified_stmt(double_inheritance_sql) {
Statement::CreateTable(CreateTable {
inherits: Some(inherits),
..
}) => {
assert_eq_vec(&["public", "parent_table"], &inherits[0].0);
assert_eq_vec(&["pg_catalog", "pg_settings"], &inherits[1].0);
}
_ => unreachable!(),
}
}
#[test]
fn parse_create_table_with_empty_inherits_fails() {
assert!(matches!(
pg().parse_sql_statements("CREATE TABLE child_table (child_column INT) INHERITS ()"),
Err(ParserError::ParserError(_))
));
}
#[test]
fn parse_create_index_concurrently() {
let sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS my_index ON my_table(col1,col2)";
@ -5426,6 +5461,7 @@ fn parse_trigger_related_functions() {
cluster_by: None,
clustered_by: None,
options: None,
inherits: None,
strict: false,
copy_grants: false,
enable_schema_evolution: None,