Skip to content

Commit 523d78e

Browse files
Support parenthesized CREATE TABLE ... (LIKE ... INCLUDING/EXCLUDING DEFAULTS) in PostgreSQL (#2242)
1 parent bd7f70e commit 523d78e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/dialect/postgresql.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,8 @@ impl Dialect for PostgreSqlDialect {
302302
fn supports_insert_table_alias(&self) -> bool {
303303
true
304304
}
305+
306+
fn supports_create_table_like_parenthesized(&self) -> bool {
307+
true
308+
}
305309
}

tests/sqlparser_postgres.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,45 @@ fn parse_create_table_constraints_only() {
593593
};
594594
}
595595

596+
#[test]
597+
fn parse_create_table_like_with_defaults() {
598+
let sql = "CREATE TABLE new (LIKE old INCLUDING DEFAULTS)";
599+
match pg().verified_stmt(sql) {
600+
Statement::CreateTable(stmt) => {
601+
assert_eq!(
602+
stmt.name,
603+
ObjectName::from(vec![Ident::new("new".to_string())])
604+
);
605+
assert_eq!(
606+
stmt.like,
607+
Some(CreateTableLikeKind::Parenthesized(CreateTableLike {
608+
name: ObjectName::from(vec![Ident::new("old".to_string())]),
609+
defaults: Some(CreateTableLikeDefaults::Including),
610+
}))
611+
)
612+
}
613+
_ => unreachable!(),
614+
}
615+
616+
let sql = "CREATE TABLE new (LIKE old EXCLUDING DEFAULTS)";
617+
match pg().verified_stmt(sql) {
618+
Statement::CreateTable(stmt) => {
619+
assert_eq!(
620+
stmt.name,
621+
ObjectName::from(vec![Ident::new("new".to_string())])
622+
);
623+
assert_eq!(
624+
stmt.like,
625+
Some(CreateTableLikeKind::Parenthesized(CreateTableLike {
626+
name: ObjectName::from(vec![Ident::new("old".to_string())]),
627+
defaults: Some(CreateTableLikeDefaults::Excluding),
628+
}))
629+
)
630+
}
631+
_ => unreachable!(),
632+
}
633+
}
634+
596635
#[test]
597636
fn parse_alter_table_constraints_rename() {
598637
match alter_table_op(

0 commit comments

Comments
 (0)