Created
February 8, 2021 13:30
-
-
Save pikonha/f221158addcd0ddf18426986d7f59ab7 to your computer and use it in GitHub Desktop.
Postgres select random N% of registers with condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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