On Wed, 28 Aug 2024 at 12:27, Andy Fan <zhihuifan1...@163.com> wrote:
> Japin Li <japi...@hotmail.com> writes:
>
>
>> Thanks for updating the patch. Here are some comments.
>>
>> +    if (minlen >= maxlen)
>> +            ereport(ERROR,
>> +                            (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
>> +                             errmsg("minlen must be greater than 
>> maxlen.")));
>>
>> There error message should be "minlen must be smaller than maxlen", right?
>>
>> +    if (minlen < 0)
>> +            ereport(ERROR,
>> +                            (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
>> +                             errmsg("minlen and maxlen must be greater than 
>> zero.")));
>>
>> Here the minlen might be zero, so the error message is incorrect.
>> How about use "minlen must be greater than or equal to zero"?
>
> Yes, you are right. A new version is attached, thanks for checking! 
>

Nitpick, the minlen is smaller than maxlen, so the maxlen cannot be zero.

After giving it some more thought, it would also be helpful if maxlen is
equal to minlen.

For example, I want have each row has four items, I can use the following

SELECT rand_array(10, 4, 4, 50::int, 80::int);

OTOH, I find the range bound uses "less than or equal to", how about
replacing "smaller" with "less"?

-- 
Regrads,
Japin Li

diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index b24c70d538..69b276b285 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -306,10 +306,10 @@ rand_array_internal(FunctionCallInfo fcinfo, Oid datatype)
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("number of rows cannot be negative")));
 
-	if (minlen >= maxlen)
+	if (minlen > maxlen)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("minlen must be smaller than maxlen.")));
+				 errmsg("minlen must be less than or equal to maxlen.")));
 
 	if (minlen < 0)
 		ereport(ERROR,

Reply via email to