How to create a table in PostgreSQL
If you're learning SQL or PostgreSQL, it's useful to know that there are several ways to create a table — depending on your use case.
-
Standard CREATE TABLE Classic method for defining schema explicitly.
-
CREATE TABLE AS (CTAS) Creates a new table from a query result.
-
LIKE Copies structure (columns, types) from another table.
-
Inheritance Less common feature — a child table inherits columns from a parent.
-
Temporary tables Session-local tables often used in ETL or analytics steps.
Examples:
CREATE TABLE users (id serial PRIMARY KEY, name text);
CREATE TABLE active_users AS SELECT * FROM users WHERE is_active = true;
CREATE TABLE archived_users (LIKE users);
CREATE TABLE premium_users (subscription_level text) INHERITS (users);
CREATE TEMP TABLE tmp AS SELECT * FROM users LIMIT 100;
If you'd like, I can post beginner-friendly breakdowns of:
• SERIAL vs IDENTITY
• Primary key patterns
• Common SELECT patterns for analytics
Posted Dec 7, 2025, 10:58 PM UTC