W3Schools PostgreSQL Data Types Guide Complete Reference Tutorial

Logan Jul 13, 2026

PostgreSQL, a robust relational database management system, provides a rich set of data types to cater to various data storage needs. W3Schools, renowned for its web tutorials, has crafted a comprehensive tutorial dedicated to PostgreSQL data types. Let's delve into the key aspects of data types in PostgreSQL, as guided by W3Schools.

SQL CAST() Explained with Examples | Convert Data Types in SQL
SQL CAST() Explained with Examples | Convert Data Types in SQL

Understanding PostgreSQL data types is crucial for efficient database schema design. It ensures the right data Precision, Scale and Nullability, which in turn affects query performance and data integrity.

SQL Data Types
SQL Data Types

Basic Data Types in PostgreSQL

PostgreSQL offers a variety of basic data types. Let's explore some of the most common ones.

PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet

Numbers - Integer Types

PostgreSQL provides several integer types like smallint, int, bigint, and numerics. These are used to store whole numbers - both positive and negative. For instance,

a cell phone with the text postgresql and other information on it
a cell phone with the text postgresql and other information on it

```sql CREATE TABLE test (i int); INSERT INTO test (i) VALUES (32000); ```

shows how to create a table with an integer column and insert a value into it.

Numbers - Decimal Types

Decimal types, like decimal(p, s), numeric(p, s), and real, are used to store exact decimal numbers. Here, `p` denotes precision, and `s` denotes scale.

a poster with different types of programming and data types on the front, including numbers, symbols
a poster with different types of programming and data types on the front, including numbers, symbols

```sql CREATE TABLE test (n numeric(5,2)); INSERT INTO test (n) VALUES (123.456789); ```

illustrates creating a numeric column and inserting a decimal value.

Date and Time Types

PostgreSQL's data types for date and time are detailed and precise. They support a wide range of date formats and operations.

Postgresql
Postgresql

Date Types

The `date` type stores dates in `YYYY-MM-DD` format. The `timestamp` type stores both date and time, from the interval `1900-01-01 00:00:00`. For example,

Tipos de Bases de Datos
Tipos de Bases de Datos
a diagram showing different types of data storage
a diagram showing different types of data storage
SQL in 60 days
SQL in 60 days
SQL & NO SQL
SQL & NO SQL
w3schools postgresql data types
w3schools postgresql data types
Learn SQL Fast 🚀 | Beginner SQL Commands Cheat Sheet for Data Analysts
Learn SQL Fast 🚀 | Beginner SQL Commands Cheat Sheet for Data Analysts
SQL Quick Notes Cheat Sheet | SQL Queries, Joins, Functions & Database Commands for Beginners
SQL Quick Notes Cheat Sheet | SQL Queries, Joins, Functions & Database Commands for Beginners
a sheet of paper that has some notes on it with words and symbols in the middle
a sheet of paper that has some notes on it with words and symbols in the middle
Sql Cheat Sheet, Learn Sql, Learn Web Development, Excel Tutorials, Sql Server, Career Options, Data Analyst, Data Scientist, Data Analysis
Sql Cheat Sheet, Learn Sql, Learn Web Development, Excel Tutorials, Sql Server, Career Options, Data Analyst, Data Scientist, Data Analysis
the different types of data structures are shown in this graphic diagram, which shows how to use
the different types of data structures are shown in this graphic diagram, which shows how to use
SQL Data Types
SQL Data Types
DSA FLOWCHART Understand → Organize → Solve → Optimize 💻✨
DSA FLOWCHART Understand → Organize → Solve → Optimize 💻✨
SQL Query Execution Order Explained | Logical Order of SQL Query Processing
SQL Query Execution Order Explained | Logical Order of SQL Query Processing
the data structure diagram shows different types of data structures and how they are used to describe them
the data structure diagram shows different types of data structures and how they are used to describe them
Master SQL for Data Analytics – Beginner to Advanced
Master SQL for Data Analytics – Beginner to Advanced
SQL Basics For Beginners
SQL Basics For Beginners
a table with the names and numbers for different types of items in front of it
a table with the names and numbers for different types of items in front of it
SQL NULLIF() Explained with Examples | Prevent Divide by Zero Errors in SQL
SQL NULLIF() Explained with Examples | Prevent Divide by Zero Errors in SQL
Programming Data types
Programming Data types
Data Types in programming languages
Data Types in programming languages

```sql CREATE TABLE test (d date, t timestamp); ```

establishes a table with date and timestamp columns.

Interval Types

The `interval` type in PostgreSQL stores the difference between two times or dates. It's useful for storing durations. For instance,

```sql CREATE TABLE test (i interval); INSERT INTO test (i) VALUES ('1 hour'); ```

shows creating an interval column and inserting a duration.

String Types

PostgreSQL offers character types to store string data. The most common ones are `char`, `varchar`, and `text`. Let's explore `varchar`:

Varying Length Strings

The `varchar(p)` type stores strings of up to `p` characters. It's efficient in terms of storage. If `p` is omitted, the default is 255. Here's an example:

```sql CREATE TABLE test (s varchar(30)); INSERT INTO test (s) VALUES ('Hello, World!'); ```

demonstrates creating a varying character column and inserting a string.

In PostgreSQL, data types are not just about storage; they influence how data is handled and queried. Understanding them is key to writing efficient SQL queries.

Get hands-on with PostgreSQL data types at W3Schools. It's a great starting point to master data types, with plenty of examples and a user-friendly interface. Give it a try, and watch your database skills grow!