`cidr` data type support
See original GitHub issueProblem
Support for the cidr PostgreSQL data type
Suggested solution
Introspecting a PostgreSQL database with a table that has a cidr column type does not list the column as unsupported. Perhaps it can devolve to a simple String field, but we would still get the type safety at the database level?
Alternatives
I suppose we could migrate our all of our cidr data types to a String and then move over to Prisma.
Additional context
Our team might be open to dedicating cycles to this change with some guidance if it is not too involved cc @dfellis
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Documentation: 15: 8.9. Network Address Types - PostgreSQL
The cidr type holds an IPv4 or IPv6 network specification. Input and output formats follow Classless Internet Domain Routing conventions. The format for ......
Read more >PostgreSQL Data Types: Network Addresses
PostgreSQL includes support for both cidr, inet, and macaddr data types. Again, those types are bundled with indexing support and advanced ...
Read more >What is CIDR (Classless Inter-Domain Routing or supernetting)?
CIDR is based on variable-length subnet masking (VLSM), which enables network engineers to divide an IP address space into a hierarchy of subnets...
Read more >Storing Network Addresses Using PostgreSQL - IBM
We're going to take a look at network address data types in PostgreSQL, namely the INET (Internet Protocol) and CIDR (Classless Internet Domain ......
Read more >Classless Inter-Domain Routing - Wikipedia
CIDR is based on variable-length subnet masking (VLSM), in which network prefixes have variable length (as opposed to the fixed-length prefixing of the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I wanted to sit and think on this, because while our immediate usage of it is primarily for the database’s input validation and normalization and the answer there is no, there are many “obvious” functions, particularly in use with the
whereclause that would need exposure in Prisma’s client to be available.For example, answering the question “get all records with IP addresses in this CIDR range for Comcast users in California (so we can comply with CCPA regulations)”
That would be something like
select * from access_logs where ip_address << '192.168.1.0/24'::cidrand the Prismawherewould need to be something like:These presumably could also go into an insert, generating a result based on an operation from queried (or supplied) data, but on that front I actually don’t see any way in the prisma client to do an
insert into ... selecton existing data? So that might be moot.Hi @janpio
Yes.
Yes, there’s a whole host of database-side input validation first of all. There are also many built-in functions to manipulate
cidrandinettypes, particularly involving containment, determining the broadcast address of the relevant cidr range, etc https://www.postgresql.org/docs/current/functions-net.htmlMariaDB has the
inet6type that is a subset of this https://mariadb.com/kb/en/inet6/ but I don’t understand the relevancy here?There are several ways to represent the
inetandcidrtypes.inetpiece could be represented as an object with keys indicating IPv4/v6 type and the address itself could be represented as a BigInt if desired instead of the usual string representation. There are also multiple equivalent string representations that convert into a single canonical string representation, particularly with IPv6.cidrcomponent could be represented as a bitmask field attached to such an object.I would like to note that the database we are trying to switch to Prisma for migrations already uses the
cidrtype, and the prisma documentation states full support of Postgres’ native types and automatic schema generation of them so we were surprised to run into this.