CREATE TABLE ParadeDB defines a new relational table named ParadeDB with chosen columns, data types, constraints, defaults, and storage settings.
CREATE TABLE ParadeDB instructs PostgreSQL to allocate disk space and metadata for a brand-new table called ParadeDB
. You specify each column’s data type, default values, constraints, and optional storage parameters so the database knows how to store and validate future rows.
Use IF NOT EXISTS
when deployment scripts might run more than once. It prevents a fatal error if ParadeDB
already exists, allowing migrations to stay idempotent and CI pipelines to keep running.
Declare PRIMARY KEY
, UNIQUE
, and REFERENCES
clauses directly after each column or in a separate table-level constraint block. This keeps data consistent from the first insert.
Append TEMPORARY
or UNLOGGED
for short-lived or bulk-load scenarios. Specify TABLESPACE
to put ParadeDB
on a dedicated volume for faster I/O or quota isolation.
The snippet below creates a table that stores parade-style daily order facts while enforcing referential integrity with the existing Orders
table.
CREATE TABLE IF NOT EXISTS ParadeDB (
parade_id SERIAL PRIMARY KEY,
order_id INT REFERENCES Orders(id) ON DELETE CASCADE,
parade_date DATE NOT NULL DEFAULT CURRENT_DATE,
total_amount NUMERIC(12,2) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
parade_id
) for clarity.NOT NULL
on all mandatory fields to avoid accidental NULL
inserts.CHECK
constraints—e.g., CHECK(total_amount >= 0)
—early to prevent bad data.COMMENT ON COLUMN
right after creation.Forgeting PRIMARY KEY
allows duplicate rows—use SERIAL PRIMARY KEY
or GENERATED
identity columns. Running the statement twice without IF NOT EXISTS
raises ERROR: relation "paradedb" already exists
.
Run \d+ ParadeDB
in psql or query information_schema.columns
to confirm column order, types, and defaults. Insert a sample row and select it back to ensure constraints behave as intended.
The command takes only a metadata lock on the new table, not on existing ones, so concurrent activity proceeds unaffected.
Yes—use ALTER TABLE ParadeDB ADD COLUMN
. However, designing the full schema up front avoids later data backfills.
No. You only need CREATE privilege on the target schema or database.
Yes, prepend TEMPORARY
to the command to drop the table automatically at session end.