postgresql - how to select IPs in same network in SQL -


i have table include ip addresses , netmasks, want select ips table in same network network address.

   ip_adress    |  netmask ----------------|-----------  192.168.13.25  |    29      192.168.13.26  |    29  192.168.13.1   |    30  192.168.13.2   |    30 

for example, want ips table in network address 192.168.13.24/29:

   ip_adress    |  netmask ----------------|-----------  192.168.13.25  |    29      192.168.13.26  |    29 

using postgresql's network address functions , operators can easly :

select * network_adresse_table  network(cast(format('%1$s/%2$s',ip_adress,netmask) inet)) =  cast('192.168.13.24/29' inet) 

here sql fiddle


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -