Answer the question
In order to leave comments, you need to log in
How to write a query in PostgreSQL that checks the range of ip addresses?
I have two fields of type inet. There is an ip address of the user. We need a query that will find a string that matches the range of ip addresses in the database.
I found in the documentation that it is possible to check for a range (if I understand correctly)
https://www.postgresql.org/docs/8.0/static/functio...
I'm not good
with SQL and I can't figure out how to make a query for this.
Please tell me how to do it?
Thanks in advance to all who respond.
Answer the question
In order to leave comments, you need to log in
For example, is the address 192.168.0.100 included in the network 192.168.0.0/24
postgres=# select inet '192.168.0.100' <<= inet '192.168.0.0/24';
?column?
----------
t
(1 row)
postgres=# select inet '192.168.2.112' >= inet '192.168.0.0' AND inet '192.168.2.112' <= inet '192.168.10.255';
?column?
----------
t
(1 row)
postgres=#
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question