Re: dotted quad netmask conversion

From: Steve Clark <sclark(at)netwolves(dot)com>
To: Jon Nelson <jnelson+pgsql(at)jamponi(dot)net>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: dotted quad netmask conversion
Date: 2010-12-07 16:34:25
Message-ID: 4CFE6211.8050101@netwolves.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/07/2010 10:30 AM, Jon Nelson wrote:
> On Tue, Dec 7, 2010 at 9:17 AM, Steve Clark<sclark(at)netwolves(dot)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
>
>
Thanks for the response Jon. I should have stated this PG 8.1.x and '&'
doesn't exist
for network functions.

select CAST('1.2.3.4' AS INET) & CAST('255.255.128.0' AS INET);
ERROR: operator does not exist: inet & inet
HINT: No operator matches the given name and argument type(s). You may
need to add explicit type casts.

--
Stephen Clark
*NetWolves*
Sr. Software Engineer III
Phone: 813-579-3200
Fax: 813-882-0209
Email: steve(dot)clark(at)netwolves(dot)com
http://www.netwolves.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-12-07 16:43:39 Re: dotted quad netmask conversion
Previous Message Gabi Julien 2010-12-07 16:31:55 Postgresql 9.1 pg_last_xact_replay_timestamp limitations