Skip to content

Instantly share code, notes, and snippets.

@pikonha
Created February 8, 2021 13:30
Show Gist options
  • Save pikonha/f221158addcd0ddf18426986d7f59ab7 to your computer and use it in GitHub Desktop.
Save pikonha/f221158addcd0ddf18426986d7f59ab7 to your computer and use it in GitHub Desktop.
Postgres select random N% of registers with condition
-- This query is taking 10% of registers that met a simple condition
select json_agg(id) from table
where
table.columnA is not null and
random() < 0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment