Re: Default ordering option - Mailing list pgsql-general

From Cyril Champier
Subject Re: Default ordering option
Date
Msg-id CAJaA8Vf58WvDmYPXNoOPgYpAuDpvP+u9uvkL2D_2mzt5MZL-nw@mail.gmail.com
Whole thread Raw
In response to Re: Default ordering option  (Julien Rouhaud <rjuju123@gmail.com>)
List pgsql-general
Julien,

Because it's production code generated by our ORM for this command: `Patient.find_by(last_name: 'champier')`.
Of course this was not intended by the developer that though the last_name was unique.



On Fri, Jul 26, 2019 at 10:10 AM Julien Rouhaud <rjuju123@gmail.com> wrote:
On Fri, Jul 26, 2019 at 9:53 AM Cyril Champier
<cyril.champier@doctolib.com> wrote:
>
> Adrian:
>
>> Are you really looking for a pseudo-random name?
>
>
> No, the code I pasted was an existing production bug: the last_name should have been unique, so the selected patient would always be the same.
> This should have been detected in tests, but since the order was "almost always the same", our test was green 99% of the time, so we discarded it as flaky.

If the filter should return at most 1 row, why put a LIMIT in the
first place?  Even with a forced random() you won't get a failure
every time, while asserting there's at most 1 row returned is
guaranteed to fail?

pgsql-general by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: Default ordering option
Next
From: Thomas Kellerer
Date:
Subject: Re: Too slow to create new schema and their tables, functions,triggers.