QuickDevGuide

Home › PostgreSQL Database

Create Database & Tables — PostgreSQL Database

In PostgreSQL, a database is a collection of schemas, and each schema contains tables, views, functions, and other objects. The default schema is public. Creating a Database Use CREATE DATABASE to create a new database. You can specify encoding, locale, and template: Creating Tables Tables are defined with CREATE TABLE. PostgreSQL supports a rich set of data types: Category Types Numeric INTEGER, BIGINT, SERIAL, NUMERIC, REAL, DOUBLE PRECISION Text VARCHAR(n), TEXT, CHAR(n) Boolean BOOLEAN Date/Time DATE, TIME, TIMESTAMP, TIMESTAMPTZ, INTERVAL JSON JSON, JSONB Other UUID, BYTEA, ARRAY, INET, CIDR, MONEY Constraints PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, and DEFAULT enforce data integrity at the database level. SERIAL vs IDENTITY PostgreSQL offers both SERIAL (legacy) and…

Key Takeaways