Re: dotted quad netmask conversion - Mailing list pgsql-general

From Jon Nelson
Subject Re: dotted quad netmask conversion
Date
Msg-id AANLkTimcbum+Kccyr4BDFmC61wsES5bu-HN02tCWCdSB@mail.gmail.com
Whole thread Raw
In response to dotted quad netmask conversion  (Steve Clark <sclark@netwolves.com>)
Responses Re: dotted quad netmask conversion  (Steve Clark <sclark@netwolves.com>)
List pgsql-general
On Tue, Dec 7, 2010 at 9:17 AM, Steve Clark <sclark@netwolves.com> wrote:
> Hello All,
>
> I am working with a postgresql database that has two columns.
> One for an ip address and another for the netmask. Both of these
> columns are char varying(30). I would like to convert to just
> one column as inet. Any one know a slick way to convert the
> dotted quad netmask, E.G. 255.255.128.0, to number of bits. I didn't
> see any way directly looking at the network functions in the PG
> documentation.


select '1.2.3.4'::inet & '255.255.128.0'::inet;
or
select CAST('1.2.3.4' AS INET) & CAST('255.255.128.0' AS INET);

Be aware that CIDR representation is not as granular as netmask.

http://www.postgresql.org/docs/8.4/interactive/functions-net.html

--
Jon

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: regexp err msg question
Next
From: "Gauthier, Dave"
Date:
Subject: Re: regexp err msg question