PostgreSQL Tutorial
Data Types
Querying & Filtering Data
Managing Tables
Modifying Data
Conditionals
Control Flow
Transactions & Constraints
Working with JOINS & Schemas
Roles & Permissions
Working with Sets
Subquery & CTEs
User-defined Functions
Important In-Built Functions
PostgreSQL PL/pgSQL
Variables & Constants
Stored Procedures
Working with Triggers
Working with Views & Indexes
Errors & Exception Handling
PostgreSQL offers a rich set of native data types for users. Here's an overview of some of the most commonly used data types in PostgreSQL:
Numeric Types:
Character Types:
Binary Data Types:
Date/Time Types:
Boolean Type:
true
, false
, or null
.Enumerated Types:
Geometric Types:
Bit Strings:
Text Search Type:
UUID Type:
JSON Types:
JSON
stores data as plain text, JSONB
stores it in a binary format.Array Types:
Composite Types:
OIDs (Object Identifiers):
Range Types:
Domain Types:
Network Address Types:
These are just some of the primary data types available in PostgreSQL. The database also supports the creation of custom data types using the CREATE TYPE
command. Always choose the data type that best fits the nature and range of the data you're storing. This ensures optimal storage efficiency and query performance.
Numeric data types in PostgreSQL:
INTEGER, SMALLINT, BIGINT, DECIMAL, NUMERIC, REAL, DOUBLE PRECISION
Character data types in PostgreSQL:
VARCHAR(n), CHAR(n), TEXT
Date and time data types in PostgreSQL:
DATE, TIME, TIMESTAMP, INTERVAL
Binary data types in PostgreSQL:
BYTEA
Array data types in PostgreSQL:
INTEGER[], VARCHAR[], TEXT[]
JSON and JSONB data types in PostgreSQL:
JSON, JSONB
Geometric data types in PostgreSQL:
POINT, LINE, LSEG, BOX, PATH, POLYGON, CIRCLE
Network address data types in PostgreSQL:
INET, CIDR, MACADDR
Custom and composite data types in PostgreSQL:
CREATE TYPE custom_type AS (field1 INT, field2 VARCHAR);
Choosing the right data types in PostgreSQL:
-- Choose appropriate data types based on requirements
Working with ENUM data types in PostgreSQL:
CREATE TYPE status AS ENUM ('active', 'inactive', 'pending');
Handling NULL values with data types in PostgreSQL:
CREATE TABLE your_table ( column1 INTEGER, column2 VARCHAR NULL, column3 DATE NOT NULL );