CREATE TABLE
Anatomy of a Robust CREATE TABLE
CREATE TABLECREATE TABLE users (
-- 1. Identity Columns
user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- 2. Data Columns with Constraints
username VARCHAR(50) NOT NULL UNIQUE,
email TEXT NOT NULL CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'),
age INT DEFAULT 18,
-- 3. Metadata for Data Engineering
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
)
WITH (fillfactor = 90); -- Storage parameter to leave room for UPDATESAdvanced Creation Methods
A. CREATE TABLE AS (CTAS)
CREATE TABLE AS (CTAS)B. CREATE TABLE ... (LIKE ...)
CREATE TABLE ... (LIKE ...)Temporary Tables
Column Properties & Identities
Summary Checklist
Demonstration: Table Structure
Partitioned Tables (Declarative Partitioning)
The Syntax Difference
Last updated