> > # SELECT y FROM x WHERE y = chr(round(random())::int + 65);
> > y
> > ---
> > A
> > B
> > (2 rows)
> Here you got a random value in the lower range of 0..1 for the record with
> value ‘A’, so that’s a match, and one in the higher range for value ‘B’, a
> match again, so you get 2 rows.
No,
On Tue, May 07, 2019 at 12:17:12PM +, Daniel Perrett wrote:
> The WHERE expression (and therefore the random function) is being evaluated
> once per row, not once per query.
> If you run this query a few times, you will see the problem:
> SELECT y, chr(round(random())::int + 65) FROM (SELECT '
PROBLEM:
Strings or characters generated by any random function (including pg_crypto
gen_random_bytes) are matching a string/char index in surprising ways.
Reduced down to its simplest example:
-- use random 0 or 1, plus 65, to get 'A' or 'B'
# SELECT chr(round(random())::int + 65);
chr
-
B