I am working on PostgeSQL with PHP.
Is it possible to select a certain number of random values in the FROM table column WHERE clause
instead
select column FROM table WHERE condition
then convert them to an array and use array_rand()?
(I do not want to use this path, because I will have millions of rows and first select all the values, and it array_rand()will probably take a lot of time.)
Let's say I have a table like this:
name | items
Ben | {dd,ab,aa}
David | {dd,aa}
Bryan | {aa,ab,cd}
Glen | {cd}
Edward | {aa,cd}
Aaron | {dd,aa}
..... (many many more)
Update:
And I need to select 10 random values in a column (or basically 10 random rows) that match the condition (in this case it will @> ARRAY[aa]) without sequentially scanning the table or something that is time consuming.
order by random() , , .
user1282226