Data Types — Complete Guide
Data Types — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of PostgreSQL Tutorial on Toolliyo Academy.
On this page
PostgreSQL Tutorial · Lesson 8 of 100
Data Types
SQL → Advanced
SQL · 1 — Queries · ~6 min · PostgreSQL — Foundations
What is this?
PostgreSQL offers rich types beyond VARCHAR and INT — timestamptz, uuid, jsonb, arrays, ranges, and numeric for money. Picking the right type prevents rounding bugs and timezone confusion.
Why should you care?
A Flipkart price stored as float causes ₹99.99 to become ₹99.989999; numeric(10,2) and timestamptz for delivery slots avoid production incidents.
See it live — copy this example
Run in pgAdmin or psql.
CREATE TABLE products (
product_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name text NOT NULL,
price numeric(10,2) NOT NULL,
tags text[] DEFAULT '{}',
specs jsonb DEFAULT '{}'
);
What happened?
- uuid with gen_random_uuid() gives globally unique ids.
- numeric holds exact decimals.
- text[] stores tag lists.
- jsonb stores flexible specs with binary efficiency.
Practice next
- Create products table in PostgresVerse.
- Insert one row with tags ARRAY['electronics','sale'] and specs '{"warranty":"1y"}'::jsonb.
- Select tags[1] and specs->>'warranty' to extract values.
- Add a daterange column for promotion validity and insert '[2026-01-01,2026-03-01)'.
- Cast a string to inet type for storing customer IP addresses.
Remember
numeric is for money; float is for science. jsonb indexes well; json is storage-only. Arrays and uuid reduce join complexity for tags and ids.
PostgresVerse catalog types
Merchandising stores variant specs in jsonb while keeping SKU price as numeric for GST calculations.
Outcome: Finance reports match payment gateway amounts to the paisa.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!