Cockroach: sql: Support CIDR column type

Created on 27 Sep 2017  路  1Comment  路  Source: cockroachdb/cockroach

The CIDR column type for dealing with IP addresses in postgresql. It's closely related to the INET column type with some minor differences.

  • It truncates the IP address bits that aren't in the prefix length when casting from INET
  • It doesn't allow IP addresses with bits past the prefix length when parsing (/casting from string)

Many of the same functions for INET are supported by CIDR, either by casting it to an INET or from CIDR with a few differences, e.g.

  • abbrev omits octets with no bits set (or not covered at all by the prefix length, you'd have to check postgres to determine that)
  • set_masklen truncates bits not covered by the prefix length
  • network returns a CIDR but consumes an INET

See the postgres docs for features
https://www.postgresql.org/docs/current/static/datatype-net-types.html
https://www.postgresql.org/docs/current/static/functions-net.html

A-sql-datatypes A-sql-semantics C-enhancement E-starter X-anchored-telemetry

Most helpful comment

I notice INET type is in 2.0, but apparently not CIDR - will this be coming? Applications such as Netbox need both...
To add to that, CRDB is targeted at distributed network-based applications - INET and CIDR datatypes are perfect for managing all kinds of things in this domain.
... not to mention that not having CIDR is an empty checkbox for any claimed Postgres compatibility. I would assume that Postgres added these datatypes because there was a need; if PG had the need, it can only be more of a need for the network-distributed CRDB.

>All comments

I notice INET type is in 2.0, but apparently not CIDR - will this be coming? Applications such as Netbox need both...
To add to that, CRDB is targeted at distributed network-based applications - INET and CIDR datatypes are perfect for managing all kinds of things in this domain.
... not to mention that not having CIDR is an empty checkbox for any claimed Postgres compatibility. I would assume that Postgres added these datatypes because there was a need; if PG had the need, it can only be more of a need for the network-distributed CRDB.

Was this page helpful?
0 / 5 - 0 ratings