JOINing based on whether an IP address is contained within a CIDR range?

Поиск
Список
Период
Сортировка
От Jamie Tufnell
Тема JOINing based on whether an IP address is contained within a CIDR range?
Дата
Msg-id b0a4f3350710251122y10648d4id322f12a81001c07@mail.gmail.com
обсуждение исходный текст
Ответы Re: JOINing based on whether an IP address is contained within a CIDR range?  (Erik Jones <erik@myemma.com>)
Re: JOINing based on whether an IP address is contained within a CIDR range?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hi,<br /><br />I am storing a log of HTTP requests in a database table (including IP address):<br /><br />http_log:
id(PK),path, time, ip<br /><br />I have another table that contains CIDR ranges and names for them:<br /><br
/>network_names:id(PK), cidr, name <br /><br />Some example data for both tables:<br /><br />network_names:<br />1, <a
href="http://192.168.0.0/24">192.168.0.0/24</a>,'Engineering'<br />2, <a
href="http://192.168.1.0/24">192.168.1.0/24</a>,'Media'<br /> 3, <a href="http://192.168.2.0/24">192.168.2.0/24</a>,
'Engineering'<br/>4, <a href="http://192.168.3.0/24">192.168.3.0/24</a>, 'Accounting'<br />5, <a
href="http://192.168.4.0/24">192.168.4.0/24</a>,'Engineering' <br />6, <a href="http://10.0.0.0/8">10.0.0.0/8</a>,
'Engineering'<br/><br />http_log:<br />1, '/index.html', 110000001, <a
href="http://192.168.0.47/32">192.168.0.47/32</a><br/> 2, '/index.html', 110000023, <a
href="http://200.1.2.3/32">200.1.2.3/32</a><br/> 3, '/index.html', 110000059, <a
href="http://1.2.3.4/32">1.2.3.4/32</a><br/> 4, '/index.html', 110000232, <a
href="http://192.168.2.1/32">192.168.2.1/32</a><br/> 5, '/index.html', 113919102, <a
href="http://192.168.1.39/32">192.168.1.39/32</a><br/> 6, '/index.html', 129101293, <a
href="http://10.2.2.4/32">10.2.2.4/32</a><br/> 7, '/index.html', 132828282, <a
href="http://192.168.4.2/32">192.168.4.2/32</a><br/><br />Now, in trying to produce a report on this data, I've come up
againstan interesting (to me at least!) problem..<br /><br />I basically want the same output as in http_log, but
substitutingthe IP with the network name where available, i.e:<br /><br />1, '/index.html', 110000001, Engineering<br
/>2, '/index.html', 110000023, <a href="http://200.1.2.3/32">200.1.2.3/32</a><br /> 3, '/index.html', 110000059, <a
href="http://1.2.3.4/32">1.2.3.4/32</a><br/> 4, '/index.html', 110000232, Engineering<br /> 5, '/index.html',
113919102,Media<br /> 6, '/index.html', 129101293, Engineering<br /> 7, '/index.html', 132828282, Engineering<br /><br
/>I'mwondering what the best way of doing this is (considering that http_log could have >100000 rows)  Is it
possibleto somehow JOIN using the <<= and >>= network operators?  Or would I have to iterate the
network_namestable manually with LOOP (or something) on every row of the http_log? <br /><br />If anyone can share some
advice,that would be great!<br /><br />Thanks,<br />JST<br /> 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: (repost) Help understanding expressions in order by clause
Следующее
От: "Chuck D."
Дата:
Сообщение: Re: request for help with COPY syntax