CREATE TABLE defines a new, permanently stored table with chosen distribution and sort keys in Amazon Redshift.
CREATE TABLE materializes a dataset inside your Redshift cluster, letting you control column types, compression, distribution, and sort order for fast analytics.
The command starts with CREATE TABLE, an optional IF NOT EXISTS clause, column definitions, and table-level options such as DISTKEY and SORTKEY.
Specify column_name followed by Redshift data types (INTEGER, VARCHAR(n), BOOLEAN, etc.). Add DEFAULT, IDENTITY, or ENCODE options to optimize storage and loading.
Use DISTKEY on columns heavily joined across large tables (e.g., customer_id). Choose SORTKEY columns frequently filtered or ordered (e.g., order_date) to speed up scans.
Mostly yes, but adjust Redshift-specific features (DISTKEY, SORTKEY, ENCODE). Also replace serial with IDENTITY.
CREATE TABLE IF NOT EXISTS public.orders (
id INT IDENTITY(1,1),
customer_id INT NOT NULL,
order_date DATE DEFAULT CURRENT_DATE,
total_amount NUMERIC(10,2) ENCODE az64,
DISTKEY(customer_id),
SORTKEY(order_date)
);
Choose compression via ANALYZE COMPRESSION on sample data. Keep SORTKEYs under four columns. Use VARCHAR lengths just large enough for data.
Omitting distribution style, creating wide VARCHARs, forgetting BACKUP NO for transient tables, and mixing DISTKEY with EVEN distribution are typical issues.
No. You must recreate the table with the new keys and copy data back (CTAS or ALTER TABLE … ALTER DISTKEY is unsupported).
Yes. If the session rolls back before commit, the new table disappears.
KEY co-locates rows by a chosen column; ALL replicates the entire small table to every node, ideal for static dimension tables.