diff --git a/pkg/sql/catalog/tabledesc/table.go b/pkg/sql/catalog/tabledesc/table.go index 6da84a050b8e..caee0dc0fd56 100644 --- a/pkg/sql/catalog/tabledesc/table.go +++ b/pkg/sql/catalog/tabledesc/table.go @@ -281,6 +281,10 @@ func EvalShardBucketCount( if paramVal != nil { shardBuckets = paramVal } + // Check if shardBuckets is NULL + if shardBuckets == tree.DNull { + return 0, pgerror.Newf(pgcode.InvalidParameterValue, invalidBucketCountMsg, "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 9d1f8a68c0b6..7a371a700152 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_table +++ b/pkg/sql/logictest/testdata/logic_test/create_table @@ -737,6 +737,10 @@ CREATE TABLE t_bad_param ( a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = 5 WITH (bucket_count=5) ); +statement error pq: hash sharded index bucket count must be in range \[2, 2048\], got 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 (