diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 179806465..abc554592 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -31913,11 +31913,15 @@ static void CheckPartitionExpr(Node* expr, int* colCount) if (expr == NULL) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("The expr can't be NULL"))); if (expr->type == T_A_Expr) { - char* name = strVal(linitial(((A_Expr*)expr)->name)); + A_Expr* a_expr = (A_Expr*)expr; + if (a_expr->name == NULL) { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("The expr is not supported for Partition Expr"))); + } + char* name = strVal(linitial(a_expr->name)); if (strcmp(name, "+") != 0 && strcmp(name, "-") != 0 && strcmp(name, "*") != 0) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("The %s operator is not supported for Partition Expr", name))); - CheckPartitionExpr(((A_Expr*)expr)->lexpr, colCount); - CheckPartitionExpr(((A_Expr*)expr)->rexpr, colCount); + CheckPartitionExpr(a_expr->lexpr, colCount); + CheckPartitionExpr(a_expr->rexpr, colCount); } else if (expr->type == T_FuncCall) { char* validFuncName[MAX_SUPPORTED_FUNC_FOR_PART_EXPR] = {"abs","ceiling","datediff","day","dayofmonth","dayofweek","dayofyear","extract","floor","hour", "microsecond","minute","mod","month","quarter","second","time_to_sec","to_days","to_seconds","unix_timestamp","weekday","year","yearweek","date_part","div"}; diff --git a/src/test/regress/input/partition_expr_key.source b/src/test/regress/input/partition_expr_key.source index e55b2923e..c222a4f59 100644 --- a/src/test/regress/input/partition_expr_key.source +++ b/src/test/regress/input/partition_expr_key.source @@ -10,6 +10,7 @@ create table testlistpart(a int, b int) partition by list(int4mul(a,2)) (partiti create table testhashpart(a int, b int) partition by hash(int4mul(a,2)) (partition p0 ,partition p1); create table testrangepart(a int, b int) partition by range(a,b*2) (partition p0 values less than(100,1000),partition p1 values less than(200,2000)); create table testrangepart(a int, b int) partition by range(a*2,b) (partition p0 values less than(100,1000),partition p1 values less than(200,2000)); +CREATE TABLE test_error_table0 ( column62 INT ) PARTITION BY HASH ( NOT TRUE ) ; CREATE TABLE testrangepart(a date) PARTITION BY RANGE (a*2) INTERVAL ('1 month') ( PARTITION p0 VALUES LESS THAN ('2020-03-01'), diff --git a/src/test/regress/output/partition_expr_key.source b/src/test/regress/output/partition_expr_key.source index d961364a1..f56d1cf48 100644 --- a/src/test/regress/output/partition_expr_key.source +++ b/src/test/regress/output/partition_expr_key.source @@ -19,6 +19,8 @@ create table testrangepart(a int, b int) partition by range(a,b*2) (partition p0 ERROR: The multi partition expr keys are not supported. create table testrangepart(a int, b int) partition by range(a*2,b) (partition p0 values less than(100,1000),partition p1 values less than(200,2000)); ERROR: The multi partition expr keys are not supported. +CREATE TABLE test_error_table0 ( column62 INT ) PARTITION BY HASH ( NOT TRUE ) ; +ERROR: The expr is not supported for Partition Expr CREATE TABLE testrangepart(a date) PARTITION BY RANGE (a*2) INTERVAL ('1 month') ( PARTITION p0 VALUES LESS THAN ('2020-03-01'),