Logo

dev-resources.site

for different kinds of informations.

Network Address Types in PostgreSQL. Why you need to know?

Published at
5/20/2023
Categories
postgres
datatypes
networking
ipv4
Author
muhammadzeeshan03
Author
17 person written this
muhammadzeeshan03
open
Network Address Types in PostgreSQL. Why you need to know?

Difference between data types and network address types in PostgrSQL.

Along with data types PostgreSQL offers some other data types called network address types. So, the difference between other data types and network address types is that network address types are used to store IPV4, IPV6 and MAC addresses. while other data types are simple data types like any other programming language supports.

There are four network address types.

  • inet
  • cidr
  • macaddr
  • macaddr8

inet

This network address type holds IPV4 and IPV6 host address, and optionally its subnet, all in one field. It takes 7 or 19 bytes of storage. Subnet is basically represented by the total number of network address bits present in the host. For example, if the subnet is 32 and the address is IPV4, then it represents a single host, not the subnet. And similarly for IPV6, the address length is 128 bits. So, 128 bits uniquely represent a host address.
Input format is address/y. Where address is an IPV4 or IPV6 address and y is the number of bits in the subnet. If /y is not given then it represents a single host.

cidr

This network address type only holds IPV4 or IPV6 networks. Main thing about this is input and output format follow classless internet domain routing. Its format is almost same that of inet. If /y is not given then it represents a single host.

So, whats the difference?

The main difference between inet and cidr is that unlike cidr, inet accepts nonzero bits to the right of the netmask.

For example network address.

192.168.0.1/24

is valid for inet but not for cidr.

macaddr

As the name suggests, macaddr stores the MAC addresses. For example Ethernet card hardware addresses.
So, it accepts inputs of the following formats.

'08:00:2b:01:02:03'
'08-00-2b-01-02-03'
'08002b:010203'
'08002b-010203'
'0800.2b01.0203'
'0800-2b01-0203'
'08002b010203'
Enter fullscreen mode Exit fullscreen mode

These examples all specify the same address. It accepts both capital and lower case letter for a to f.

macaddr8

This type of network address types also stores MAC addresses but in EUI-64 format. Main thing about this is, it can accept both 6 and 8 bytes length and stores them in fixed length of 8 bytes, with 4th and 5th bytes set to FF and FE.

Following are the examples of this,

'08:00:2b:01:02:03:04:05'
'08-00-2b-01-02-03-04-05'
'08002b:0102030405'
'08002b-0102030405'
'0800.2b01.0203.0405'
'0800-2b01-0203-0405'
'08002b01:02030405'
'08002b0102030405'
Enter fullscreen mode Exit fullscreen mode

Same like macaddr these all examples specify the same address. same like macaddr it can accept both upper and lower case for the digit a to f in the input.

That was a short introduction about network address types that PostgreSQL additionally supports along with other data types. To read in more details you can check reference.

Reference

https://www.postgresql.org/docs/14/datatype-net-types.html

datatypes Article's
30 articles in total
Favicon
14. Longest Common Prefix - Using Trie
Favicon
Variables & Data types
Favicon
Handling Data in SQL: Signed vs. Unsigned Types
Favicon
Representação numérica na computação
Favicon
Understanding Floats in Python: Essential Tips and Examples
Favicon
Everything You Need to Know About Python Integers: Tips, Tricks, and Examples
Favicon
Understanding Python Data Types: A Comprehensive Guide
Favicon
Why I Revisited MS SQL Server Basics: A Deep Dive into String Data Types
Favicon
Understanding Data Types in JavaScript
Favicon
Disjoint Unions in C
Favicon
PYTHON-FUNDAMENTALS: CONSTANTS, VARIABLES AND DATA TYPES
Favicon
Understanding Your Data: The Essentials of Exploratory Data Analysis"
Favicon
Data Types of Typescript
Favicon
C# {Data Types except Int}
Favicon
Variables, Constants, Data Types, and Namespaces in C++
Favicon
Data Types in Python
Favicon
JS Data types (Ma'lumot turlari)
Favicon
Data Types
Favicon
C# da ratsional sonlar bilan ishlovchi (float, double, decimal) ma'lumot turlari
Favicon
Big Integer in Java
Favicon
Oracle Data Types: An Overview
Favicon
Understanding Float vs. Double in C and C++
Favicon
Data Types - Python
Favicon
The Art of Series Summation in C: Navigating Data Types, Casting Magic, and the Dance of Incrementation
Favicon
Understanding Why We Don't Use Pointers to change the value of the element in Slice Data Type in Go Lang!
Favicon
A step by step guide to Converting a Column to Date Data Type in a Dataset using R
Favicon
Choosing the Right Java Data Types
Favicon
Evolution of Ruby Data Types
Favicon
Composite Data types part 1
Favicon
Network Address Types in PostgreSQL. Why you need to know?

Featured ones: