with swh_count_origins as ( select value from object_counts where object_type='origin' ), swh_random_id as ( select floor(random() * (select * from swh_count_origins))::int ) select * from origin where id=(select * from swh_random_id);