diff --git a/pkg/sql/catalog/tabledesc/table.go b/pkg/sql/catalog/tabledesc/table.go index 2776f80a6042..32e6cf137660 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 e4b27de1c690..68adc79e2d0f 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 (