Re: BUG #15800: Order by random in functions

From: Alessio Gennari <alessio(dot)gennari78(at)gmail(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15800: Order by random in functions
Date: 2019-05-15 08:59:46
Message-ID: CAG0sfBU_x2JGv1yWBTOt1V4hAR1shfTp8YZHKSTnx-vavLL2Sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Ok,
thank you very much.

Alessio

On Mon, 13 May 2019 at 09:57, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
wrote:

> >>>>> "PG" == PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
>
> PG> in version 9.5 (select version(): PostgreSQL 9.5.12 on
> PG> x86_64-pc-linux-gnu (Debian 9.5.12-1.pgdg80+1), compiled by gcc
> PG> (Debian 4.9.2-10+deb8u1) 4.9.2, 64-bit) this statement returns
> PG> element (id_card_type) randomly ordered:
>
> PG> select jsonb_array_elements('[...]')...order by random()
>
> PG> While in version 9.6 (PostgreSQL 9.6.12 on x86_64-pc-linux-gnu,
> PG> compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit)
> PG> and above (I tested it in Postgres 10.8) the query return elements
> PG> not ordered but in the same sequence as it is in json array.
>
> PG> Is it a bug or an expected behavior?
>
> Expected behavior, though I'm not sure it's adequately documented.
>
> The preferred way to do this is:
>
> SELECT a.value->>'id_card_type'
> FROM jsonb_array_elements('[...]') a
> ORDER BY random();
>
> which will randomize the order regardless of postgresql version.
>
> --
> Andrew (irc:RhodiumToad)
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Daniel Gustafsson 2019-05-15 09:53:51 Re: BUG #15805: Problem with lower function for greek sigma (Σ) letter
Previous Message Amit Langote 2019-05-15 08:07:46 Re: inconsistent results querying table partitioned by date