Posts

Showing posts from May, 2019

PostgreSQL Data Types - I

Image
The data type defines what type of data can contain a column. PostgreSQL database is very rich in native data types. It supports all data types specified by SQL and you can add new type using CREATE TYPE command. PostgreSQL support data types to store geometric data, XML data and network address data. We can use arrays, hstore and JSON data types to make things more dynamics. In this post we are going to look at inet and point data types in PostgreSQL. INET Data Type: The INET type is used when you want to store IPv4 or IPv6 addresses. It can also store networks by specifying a netmask. If you try to store something that isn't a valid IP address or network, PostgreSQL will throw an error, so you're basically getting data validation for free. There are a variety of methods you can use in your SQL queries to interrogate IP and network addresses further. postgres=# CREATE TABLE addrs (address INET); CREATE TABLE postgres=# INSERT INT