PostgreSQL Data types explained…

There are many data types that can be used with PostgreSQL, but there a few main categories that you need to know that’ll cover most of them. The five main data groups are Booleans, Characters, Numbers, Temporals, and Arrays.

Boolean data types can take in one of three inputs true, false or null.

Character data types have a few different types. Char is a fixed length string of characters. Varchar is a varying length string of characters that you can set the maximum length of the input. Text is a string of characters that is unlimited in length.

Number data types are made of floating point numbers and integers. Integer data types are integers or serial. Serial will be used to auto increment a number, so is very useful when assigning an ID in PostgreSQL. Floating point numbers are decimal digits.

Temporal data types are made up of date which stores dates. Time which stores only the time of the day. Timestamp which will actually do what both date and time would do and store both values in one place. Intervals is the last one, which store periods of time.

Array data types is the last group. You can store many different types of arrays which could be useful when storing multiple values in one position of a column.

Here is a example of a few data types in action..

CREATE TABLE Movies (
MoviesID serial NOT NULL,
Title varchar(100),
Year int,
Genre varchar(100),
);

When working with PostgreSQL it is very useful to not only know the different data types, but also to understand what they do and when to use them.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.