最大INET/CIDR考慮查詢:如何查詢分鐘或者Postgres的
select min(d) from temp;
select max(d) from temp;
任一個,我得到一個錯誤,如:
# select max(d) from temp;
ERROR: function max(inet) does not exist
LINE 1: select max(d) from temp;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
所以,我創建一個表所謂的氣溫和填充它:
create table temp (d inet);
insert into temp (d) values ('1.1.10.2');
insert into temp (d) values ('1.1.10.10');
insert into temp (d) values ('1.1.10.20');
insert into temp (d) values ('1.1.10.100');
# select * from temp order by d;
d
------------
1.1.10.2
1.1.10.10
1.1.10.20
1.1.10.100
(4 rows)
所以,我可以使用主機()轉換爲文本,而是產生不正確的答案:
select min(host(d)) from temp;
那是因爲它是做一個文本「分鐘」功能,這是這個順序:
# select host(d) as r from temp order by r;
r
------------
1.1.10.10
1.1.10.100
1.1.10.2
1.1.10.20
(4 rows)
是否有在Postgres的IP類型一分鐘()和MAX()函數?有辦法來欺騙它(轉換爲int並進行比較,或者通過限制進行排序)。我對適當的min()和max()更感興趣。謝謝你這麼!
-g
我讀到這http://www.postgresql.org/message-id/[email protected]om和我認爲已經有一個補丁修復了這個問題。但我嘗試了PG9.3它失敗了,我的朋友試圖在9.4它失敗too.i認爲你可以做的是映射到int和使用min()在那 –