Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTyCO-0046OO-TK for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jul 2024 06:31:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sTyCM-0071gU-PU for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jul 2024 06:31:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTyCM-0071gL-Fo for pgsql-hackers@lists.postgresql.org; Wed, 17 Jul 2024 06:31:34 +0000 Received: from m15.mail.163.com ([45.254.50.219]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sTyCH-002Seh-9X for pgsql-hackers@lists.postgresql.org; Wed, 17 Jul 2024 06:31:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=f8DrsiOT/m11Xk4hppQ9YWIEETuH0GoDKVkVWu0gQIM=; b=EEhhnQo6My7zFsrtbLRKxjL70Mo/3VW+G0l8e+PSuwM6xGzF/HrT4llwDaF2Bx xdpFLcp1AGxvbEcVks1EtTTzEECO7L4JY9fwEaVip25GXsFpWh2886syWCb+lX4S wyc8QB+QuwKl3vZm01uaCKsBLstjpsqVIbVcPrO8Y6Xac= Received: from lovely-coding (unknown [101.227.46.166]) by gzga-smtp-mta-g0-0 (Coremail) with SMTP id _____wDn13E7ZZdm_DIWDQ--.30392S3; Wed, 17 Jul 2024 14:31:23 +0800 (CST) From: Andy Fan To: Jim Jones , Postgres hackers Subject: Re: New function normal_rand_array function to contrib/tablefunc. In-Reply-To: <871q46u560.fsf@163.com> (Andy Fan's message of "Sat, 06 Jul 2024 19:32:39 +0800") References: <87plssezpc.fsf@163.com> <871q46u560.fsf@163.com> Date: Wed, 17 Jul 2024 14:31:22 +0800 Message-ID: <87r0bswmv9.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDn13E7ZZdm_DIWDQ--.30392S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw1rZryxKr18Xw4UuFWxJFb_yoW5Ww4fpa sxJFy2kr4DGr47Gw12y3WrJayUX395JF1DXrn8J340qan8ur1fAa1DKryxKryUu3y8Jr1U J3WUt3Z7ZF1jya7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRoUDXUUUUU= X-Originating-IP: [101.227.46.166] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBhR0fU2WXv79POwAAsS List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andy Fan writes: (just noticed this reply is sent to Jim privately, re-sent it to public.) > Hi Jim, > >> >> When either minval or maxval exceeds int4 the function cannot be >> executed/found >> >> SELECT * FROM normal_rand_array(5, 10, 8, 42::bigint); >> >> ERROR:=C2=A0 function normal_rand_array(integer, integer, integer, bigin= t) >> does not exist >> LINE 1: SELECT * FROM normal_rand_array(5, 10, 8, 42::bigint); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^ >> HINT:=C2=A0 No function matches the given name and argument types. You m= ight >> need to add explicit type casts. >> --- >> >> SELECT * FROM normal_rand_array(5, 10, 8::bigint, 42); >> >> ERROR:=C2=A0 function normal_rand_array(integer, integer, bigint, intege= r) >> does not exist >> LINE 1: SELECT * FROM normal_rand_array(5, 10, 8::bigint, 42); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^ >> HINT:=C2=A0 No function matches the given name and argument types. You m= ight >> need to add explicit type casts. >> --- > >> >> However, when both are int8 it works fine: > > I defined the function as below: > > postgres=3D# \df normal_rand_array > List of functions > Schema | Name | Result data type | Argument data = types | Type=20 > --------+-------------------+------------------+-------------------------= -----------------+------ > public | normal_rand_array | SETOF anyarray | integer, integer, anyele= ment, anyelement | func > (1 row) > > so it is required that the 3nd and 4th argument should have the same > data type, that's why your first 2 test case failed and the third one > works. and I also think we should not add a test case / document for > this since the behavior of 'anyelement' system. > This issue can be fixed with the new API defined suggested by Dean.=20 >> >> SELECT * FROM normal_rand_array(5, 10, 8::bigint, 42::bigint); >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 normal_rand_array=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 >> -------------------------------------------------- >> =C2=A0{29,38,31,10,23,39,9,32} >> =C2=A0{8,39,19,31,29,15,17,15,36,20,33,19} >> =C2=A0{15,18,42,19} >> =C2=A0{16,31,33,11,14,20,24,9,12,17,22,42,41,24,11,41} >> =C2=A0{15,11,36,8,28,37} >> (5 rows) >> --- >> >> Is it the expected behaviour? > > Yes, see the above statements. > >> >> In some cases the function returns an empty array. Is it also expected? >> >> SELECT count(*) >> FROM normal_rand_array(100000, 10, 8, 42) i >> WHERE array_length(i,1) IS NULL; >> >> =C2=A0count >> ------- >> =C2=A0 4533 >> (1 row) > > Yes, by design I think it is a feature which could generate [] case > which should be used a special case for testing, and at the > implementation side, the [] means the length is 0 which is caused by I > choose the 'len' by random [0 .. len * 2], so 0 is possible and doesn't > confict with the declared behavior.=20 > >> In both cases, perhaps mentioning these behaviors in the docs would >> avoid some confusion. > > hmm, It doesn't take some big effort to add them, but I'm feeling that > would make the document a bit of too verbose/detailed. > > Sorry for the late respone!=20 --=20 Best Regards Andy Fan