| From: | Andy Fan <zhihuifan1213(at)163(dot)com> | 
|---|---|
| To: | Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> | 
| Subject: | New function normal_rand_array function to contrib/tablefunc. | 
| Date: | 2024-06-08 06:05:51 | 
| Message-ID: | 87plssezpc.fsf@163.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Here is a new function which could produce an array of numbers with a
controllable array length and duplicated elements in these arrays. I
used it when working with gin index, and I think it would be helpful for
others as well, so here it is.
select * from normal_rand_array(5, 10, 1.8::numeric, 3.5::numeric);
               normal_rand_array               
-----------------------------------------------
 {3.3,2.3,2.7,3.2,2.0,2.7,3.4,2.7,2.3,2.9}
 {3.3,1.8,2.9,3.4,2.0,1.8,2.0,3.5,2.8,2.5}
 {2.1,1.9,2.3,1.9,2.5,2.7,2.4,2.9,1.8}
 {2.3,2.5,2.4,2.7,2.7,2.3,2.9,3.3,3.3,1.9,3.5}
 {2.8,3.4,2.7,1.8,3.3,2.3,2.2,3.5,2.6,2.5}
(5 rows)
select * from normal_rand_array(5, 10, 1.8::int4, 3.5::int4);
          normal_rand_array          
-------------------------------------
 {3,2,2,3,4,2}
 {2,4,2,3,3,3,3,2,2,3,3,2,3,2}
 {2,4,3}
 {4,2,3,4,2,4,2,2,3,4,3,3,2,4,4,2,3}
 {4,3,3,4,3,3,4,2,4}
(5 rows)
the 5 means it needs to produce 5 rows in total and the 10 is the
average array length, and 1.8 is the minvalue for the random function
and 3.5 is the maxvalue. 
-- 
Best Regards
Andy Fan
| Attachment | Content-Type | Size | 
|---|---|---|
| v20240608-0001-Add-function-normal_rand_array-function-to.patch | text/x-diff | 11.1 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alena Rybakina | 2024-06-08 06:30:47 | Re: Vacuum statistics | 
| Previous Message | jian he | 2024-06-08 04:14:53 | Re: altering a column's collation leaves an invalid foreign key |