Skip to content

Instantly share code, notes, and snippets.

@der3k
Last active February 7, 2017 07:22
Show Gist options
  • Save der3k/96050b707472d5f894b3d4a6a7cd6015 to your computer and use it in GitHub Desktop.
Save der3k/96050b707472d5f894b3d4a6a7cd6015 to your computer and use it in GitHub Desktop.
-- https://robertomurray.co.uk/blog/2011/postgresql-find-next-available-ip-addresses/
SELECT sub.ip FROM
(SELECT set_masklen(((generate_series(1,
(2 ^ (32 - masklen('10.10.100.0/24'::cidr)))::integer - 2) +
'10.10.100.0/24'::cidr)::inet), 32) as ip) AS sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment