Skip to content

Instantly share code, notes, and snippets.

@vbilopav
Last active September 23, 2020 11:02
Show Gist options
  • Save vbilopav/d7ac47003d4a3d21365c210b0960c25e to your computer and use it in GitHub Desktop.
Save vbilopav/d7ac47003d4a3d21365c210b0960c25e to your computer and use it in GitHub Desktop.
select
g.code
from (
select generate_series as code from generate_series(1000, 9999)
) g
left outer join tbl t on g.code = t.id
where
t.id is null
order by
random() limit 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment