Skip to content

Commit 34145ee

Browse files
committed
if pk specified in col constraint, do not rewrite it into table constraint
Signed-off-by: Bugen Zhao <[email protected]>
1 parent 66cb893 commit 34145ee

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/frontend/src/catalog/purify.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,17 @@ pub fn try_purify_table_source_create_sql_ast(
117117
});
118118
}
119119

120-
// Remove primary key constraint from the column options. It will be specified with
121-
// table constraints later.
122-
column_def
123-
.options
124-
.retain(|o| !matches!(o.option, ColumnOption::Unique { is_primary: true }));
125-
126120
purified_column_defs.push(column_def);
127121
}
128122
*column_defs = purified_column_defs;
129123

130-
if row_id_index.is_none() {
131-
// User-defined primary key.
124+
// Specify user-defined primary key in table constraints.
125+
let has_pk_column_constraint = column_defs.iter().any(|c| {
126+
c.options
127+
.iter()
128+
.any(|o| matches!(o.option, ColumnOption::Unique { is_primary: true }))
129+
});
130+
if !has_pk_column_constraint && row_id_index.is_none() {
132131
let mut pk_columns = Vec::new();
133132

134133
for &id in pk_column_ids {

0 commit comments

Comments
 (0)