Re: `order by random()` makes select-list `random()` invocations deterministic - Mailing list pgsql-bugs

From Dian Fay
Subject Re: `order by random()` makes select-list `random()` invocations deterministic
Date
Msg-id CZI1U3NKCZDT.31UY6DAFGVXC5@nmfay.com
Whole thread Raw
In response to Re: `order by random()` makes select-list `random()` invocations deterministic  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: `order by random()` makes select-list `random()` invocations deterministic  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Thu Feb 29, 2024 at 12:53 AM EST, David G. Johnston wrote:
> On Wednesday, February 28, 2024, Dian Fay <di@nmfay.com> wrote:
> >
> >
> > Every `random()` invocation in the select list uses a single consistent
> > value within each returned row. Remove the `order by random()` and
> > values become randomized as expected, but it gets a bit stranger:
> >
> >
> This seems to be one of those “won’t fix” bugs that stems from the parser
> being a bit too liberal in what it accepts as valid SQL.
>
>
> https://www.postgresql.org/message-id/CAKFQuwZ3-XGfcS%2BCLTAYvPx3ARYjUxv%2B%3DYL8sOicV0nda%3DT5cA%40mail.gmail.com
>
> The fact that the gs involving expression is seen differently than the ones
> not involving gs doesn’t surprise me.
>
> David J.

Thanks, that makes sense! Any thoughts on whether it's worth a
cautionary note in the `order by` and/or random function docs since
`order by random()` is a fairly well attested solution and I'm not the
first person to run into this quirk?



pgsql-bugs by date:

Previous
From: Thomas Munro
Date:
Subject: Re: BUG #18362: unaccent rules and Old Greek text
Next
From: Tom Lane
Date:
Subject: Re: `order by random()` makes select-list `random()` invocations deterministic