On 02/11/2017 09:17 AM, Alexander Farber wrote:
I think ORDER BY RANDOM() has stopped working in 9.6.2:
words=> select unnest(ARRAY['a','b','c','d','e','f']) order by random();
unnest
--------
a
b
c
d
e
f
(6 rows)
So back to your original question:
CREATE OR REPLACE FUNCTION public.words_shuffle(in_array character
varying[])
RETURNS character varying[]
LANGUAGE sql
STABLE
AS $function$
SELECT array_agg(letters.x) FROM
(SELECT * FROM UNNEST(in_array) x ORDER BY RANDOM()) letters;
$function$
postgres=> select * from words_shuffle(ARRAY['a','b','c','d','e','f']);
words_shuffle
---------------
{d,f,a,e,c,b}
(1 row)
postgres=> select * from words_shuffle(ARRAY['a','b','c','d','e','f']);
words_shuffle
---------------
{c,d,a,e,f,b}
(1 row)
--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general