Skip to content

Commit

Permalink
fix(generated_column): correct the output message when use impure exp…
Browse files Browse the repository at this point in the history
…r in generated columns. (risingwavelabs#12494)
  • Loading branch information
yuhao-su authored Sep 22, 2023
1 parent 063f58e commit 5ab1f7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion e2e_test/ddl/table/generated_columns.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ CREATE TABLE t (v INT, t timestamptz as now()) WITH (
) FORMAT PLAIN ENCODE JSON;

# create a table with impure generated column as pk.
statement error QueryError: Bind error: Generated columns should not be part of the primary key. Here column "v2" is defined as part of the primary key.
statement error QueryError: Bind error: Generated columns with impure expressions should not be part of the primary key. Here column "v2" is defined as part of the primary key.
CREATE TABLE t (
v1 INT,
v2 timestamptz AS proctime(),
Expand Down
16 changes: 10 additions & 6 deletions src/frontend/src/handler/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,21 @@ fn check_generated_column_constraints(
.iter()
.any(|c| c == referred_generated_column)
{
return Err(ErrorCode::BindError(
format!("Generated can not reference another generated column, but here generated column \"{}\" referenced another generated column \"{}\"", column_name, referred_generated_column),
)
return Err(ErrorCode::BindError(format!(
"Generated can not reference another generated column. \
But here generated column \"{}\" referenced another generated column \"{}\"",
column_name, referred_generated_column
))
.into());
}
}

if pk_column_ids.contains(&column_id) && expr.is_impure() {
return Err(ErrorCode::BindError(
format!("Generated columns should not be part of the primary key. Here column \"{}\" is defined as part of the primary key.", column_name),
)
return Err(ErrorCode::BindError(format!(
"Generated columns with impure expressions should not be part of the primary key. \
Here column \"{}\" is defined as part of the primary key.",
column_name
))
.into());
}

Expand Down

0 comments on commit 5ab1f7a

Please sign in to comment.