Re: random generated string matching index in inexplicable ways - Mailing list pgsql-general

From Francisco Olarte
Subject Re: random generated string matching index in inexplicable ways
Date
Msg-id CA+bJJbwrBzc5H=fO-gTGtyx+UTYeb6e4yu3_pw4W016cbrYFdg@mail.gmail.com
Whole thread Raw
In response to Re: random generated string matching index in inexplicable ways  (Myles Miller <pg@q7r7.com>)
List pgsql-general
On Tue, May 7, 2019 at 3:12 PM Myles Miller <pg@q7r7.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



pgsql-general by date:

Previous
From: Steven Lembark
Date:
Subject: Re: Postgres for SQL Server users
Next
From: Frank Alberto Rodriguez
Date:
Subject: Re: duplicate key value violates unique constraint"chinese_price_infos_pkey"