Re: random generated string matching index in inexplicable ways

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Myles Miller <pg(at)q7r7(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: random generated string matching index in inexplicable ways
Date: 2019-05-07 13:52:27
Message-ID: CA+bJJbwrBzc5H=fO-gTGtyx+UTYeb6e4yu3_pw4W016cbrYFdg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 7, 2019 at 3:12 PM Myles Miller <pg(at)q7r7(dot)com> wrote:
> No, the function is returning just one letter, either 'A' or 'B', not multiple values.

Your random function is being evaluated ONCE FOR EACH ROW.

i.e, it's doing something like:
select y from
( SELECT y, chr(round(random())::int + 65) as z FROM x ) aux
WHERE y = z;
o
with aux as ( SELECT y, chr(round(random())::int + 65) as z FROM x )
select y from aux WHERE y = z;

You may want to try something like this:

with aux as ( SELECT chr(round(random())::int + 65) as z )
select y from x,aux WHERE y = z;

( Untested, but that's the idea )

Francisco Olarte

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Frank Alberto Rodriguez 2019-05-07 16:54:57 Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"
Previous Message Steven Lembark 2019-05-07 13:48:45 Re: Postgres for SQL Server users