Skip to content
Advertisement

trying to select random data PostgreSQL

I’m trying to select random strings. The problem is it returns the same value for each row. Why is that and how to fix?

10 rows

Advertisement

Answer

Postgres overoptimizes the subquery. I think this is an error, because it is missing the fact that random() is volatile.

A simple fix is a correlation clause:

I rewrote the logic a bit, so it is simpler. There is no need to use arrays for what you want to do.

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement