pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: pgsql-bugs@lists.postgresql.org
To: alessio.gennari78@gmail.com
Subject: Re: BUG #15800: Order by random in functions
Date: Mon, 13 May 2019 08:57:31 +0100
Message-ID: <87r292g58w.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <15800-5c54ab25e4c8a6ed@postgresql.org>
References: <15800-5c54ab25e4c8a6ed@postgresql.org>

>>>>> "PG" == PG Bug reporting form <noreply@postgresql.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)





view thread (3+ messages)  latest in thread

Message-ID: <87r292g58w.fsf@news-spur.riddles.org.uk>
Permalink:  ../87r292g58w.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87r292g58w.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, alessio.gennari78@gmail.com
  Subject: Re: BUG #15800: Order by random in functions
  In-Reply-To: <87r292g58w.fsf@news-spur.riddles.org.uk>
  References: <15800-5c54ab25e4c8a6ed@postgresql.org> <87r292g58w.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox