Re: [GENERAL] Custom shuffle function stopped working in 9.6 - Mailing list pgsql-general

From Adrian Klaver
Subject Re: [GENERAL] Custom shuffle function stopped working in 9.6
Date
Msg-id 53f1c2a4-bb3c-3231-6df6-3995144c718f@aklaver.com
Whole thread Raw
In response to Re: [GENERAL] Custom shuffle function stopped working in 9.6  (Alexander Farber <alexander.farber@gmail.com>)
List pgsql-general
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@aklaver.com


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] Custom shuffle function stopped working in 9.6
Next
From: Jack Christensen
Date:
Subject: Re: [GENERAL] Custom shuffle function stopped working in 9.6