Re: casting TEXT to CIDR (or to INET) has to be possible - Mailing list pgsql-bugs

From Tom Lane
Subject Re: casting TEXT to CIDR (or to INET) has to be possible
Date
Msg-id 21158.1009092173@sss.pgh.pa.us
Whole thread Raw
In response to casting TEXT to CIDR (or to INET) has to be possible  (Paul Vixie <paul@vix.com>)
List pgsql-bugs
Paul Vixie <paul@vix.com> writes:
> lartomatic=# select (host(relay)||'/18')::cidr from spam limit 5;
> ERROR:  Cannot cast type 'text' to 'cidr'
> lartomatic=# select (host(relay)||'/18')::inet from spam limit 5;
> ERROR:  Cannot cast type 'text' to 'inet'

Your wish is our command ;-).  It seems to work okay in 7.2 beta:

regression=# create table spam(relay inet);
CREATE
regression=# insert into spam values ('127.0.0.1');
INSERT 287658 1
regression=# select (host(relay)||'/18')::cidr from spam limit 5;
ERROR:  invalid CIDR value '127.0.0.1/18': has bits set to right of mask
regression=# select (host(relay)||'/18')::inet from spam limit 5;
     inet
--------------
 127.0.0.1/18
(1 row)

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Yuan Jiang \(tony\)"
Date:
Subject: PostGIS/ PostGreSQL ODBC problem
Next
From: Tom Lane
Date:
Subject: Re: Problem creating database using windows2k + cygwin + cygipc