Preparing your workspace
PostgreSQL provides a rich set of data types that help represent application data accurately and consistently.
Choosing the correct PostgreSQL data type helps protect data quality and makes queries more predictable. Common types include integer and bigint for whole numbers, numeric for exact decimal values, text and varchar for text, boolean for true or false values, date and timestamp for dates and times, uuid for unique identifiers, jsonb for structured JSON data, and arrays for lists of values. PostgreSQL also provides specialized types for advanced application needs.
A course platform may use UUID for user IDs, text for descriptions, numeric for prices, boolean for published status, and timestamptz for event times.
CREATE TABLE courses ( id UUID PRIMARY KEY, title TEXT NOT NULL, price NUMERIC(10,2) NOT NULL, published BOOLEAN NOT NULL DEFAULT false, metadata JSONB, created_at TIMESTAMPTZ NOT NULL DEFAULT now() );
The courses table stores identifiers, text, exact prices, boolean status, JSON metadata, and timezone-aware timestamps.