From 5ab1f7a2fb8bf1e0b984598d95b69b50c6410c33 Mon Sep 17 00:00:00 2001 From: Yuhao Su <31772373+yuhao-su@users.noreply.github.com> Date: Fri, 22 Sep 2023 20:30:28 +0800 Subject: [PATCH] fix(generated_column): correct the output message when use impure expr in generated columns. (#12494) --- e2e_test/ddl/table/generated_columns.slt.part | 2 +- src/frontend/src/handler/create_table.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/e2e_test/ddl/table/generated_columns.slt.part b/e2e_test/ddl/table/generated_columns.slt.part index 08f07eb88f670..feea107fe9ac1 100644 --- a/e2e_test/ddl/table/generated_columns.slt.part +++ b/e2e_test/ddl/table/generated_columns.slt.part @@ -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(), diff --git a/src/frontend/src/handler/create_table.rs b/src/frontend/src/handler/create_table.rs index 73c5f65add34c..81f60b64702f2 100644 --- a/src/frontend/src/handler/create_table.rs +++ b/src/frontend/src/handler/create_table.rs @@ -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()); }