Getting a single random row, or a few rows, from a table in order to get representative data for example is a frequent need. The most common way to do this in PostgreSQL is using ORDER BY random()
like:
SELECT id FROM data ORDER BY random() LIMIT 1
But when run on a large table this can be very slow. ... [continue reading]