diff --git a/pkg/sql/catalog/tabledesc/table.go b/pkg/sql/catalog/tabledesc/table.go index fb871851b11e..e5c5356882d6 100644 --- a/pkg/sql/catalog/tabledesc/table.go +++ b/pkg/sql/catalog/tabledesc/table.go @@ -285,6 +285,10 @@ func EvalShardBucketCount( if paramVal != nil { shardBuckets = paramVal } + // Check if shardBuckets is NULL + if shardBuckets == tree.DNull { + return 0, pgerror.Newf(pgcode.InvalidParameterValue, `"BUCKET_COUNT" cannot be NULL`) + } typedExpr, err := schemaexpr.SanitizeVarFreeExpr( ctx, shardBuckets, types.Int, "BUCKET_COUNT", semaCtx, volatility.Volatile, false, /*allowAssignmentCast*/ ) diff --git a/pkg/sql/logictest/testdata/logic_test/create_table b/pkg/sql/logictest/testdata/logic_test/create_table index 9d8971070f1a..1d5c4489c7df 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_table +++ b/pkg/sql/logictest/testdata/logic_test/create_table @@ -739,6 +739,10 @@ CREATE TABLE t_bad_param ( a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = 5 WITH (bucket_count=5) ); +statement error pq: "BUCKET_COUNT" cannot be NULL +CREATE TABLE t_bad_param ( + a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = NULL +); statement error pq: invalid storage param "s2_max_level" on primary key CREATE TABLE t_bad_param (