Thread: inet/cidr - can this be done?

inet/cidr - can this be done?

From
Mark Volpe
Date:
Is there a way to convert inet types
to cidr? I have a table with an inet
field, and it would be cool to, say,
group by class C network. My little attempt
here results in an error:

CREATE TABLE test(ip inet);
INSERT INTO test VALUES('192.168.1.2');
SELECT (host(ip) || '/24')::cidr FROM test;

ERROR:  No such function 'cidr' with the specified attributes

Thanks in advance
- Mark


Re: [SQL] inet/cidr - can this be done?

From
Peter Eisentraut
Date:
The problem is that host(ip)||'/24' isn't of the inet type, it's text. For
a simple select query you don't have to cast this at all, it would seem,
since it goes as text to the frontend either way.

Also, a straightforward cast inet_value::cidr seems to work for me.


On Sat, 29 Jan 2000, Mark Volpe wrote:

> Is there a way to convert inet types
> to cidr? I have a table with an inet
> field, and it would be cool to, say,
> group by class C network. My little attempt
> here results in an error:
> 
> CREATE TABLE test(ip inet);
> INSERT INTO test VALUES('192.168.1.2');
> SELECT (host(ip) || '/24')::cidr FROM test;
> 
> ERROR:  No such function 'cidr' with the specified attributes
> 
> Thanks in advance
> - Mark
> 
> ************
> 
> 

-- 
Peter Eisentraut                  Sernanders vaeg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden