Home > Postgresql > Selecting random single row on large table

Selecting random single row on large table

This assumes that id is your unique SERIAL field, and that {table}_id_seq is the field for the next value.

select * from {table}
where id >= (
select floor(random() * (
select last_value
from {table}_id_seq )) ) order by id asc limit 1

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Categories: Postgresql Tags:
  1. No comments yet.