liveBook · Manning

CREATE TABLE statement

As explained in Just Use Postgres!

The CREATE TABLE command is an SQL statement that creates a relational table with a specified schema.

CREATE TABLE creates a relational table by declaring its name and columns. Each column receives a data type, giving application data a defined structure. section 2.1

Create a stock-trades table

CREATE TABLE trades( id bigint, buyer_id integer, symbol text, order_quantity integer, bid_price numeric(5,2), order_time timestamp ); section 1.5

Listing 1.4 Creating a sample table
CREATE TABLE trades(
    id bigint,
    buyer_id integer,
    symbol text,
    order_quantity integer,
    bid_price numeric(5,2),
    order_time timestamp
);

Inspect the complete sample definition and its column types. section 1.5

After creation, the table can support a short mock-data workflow:

  • Use \d to list the table among existing relations. section 1.5
  • Use generate_series with INSERT to populate sample trades. section 1.5

How Just Use Postgres! covers it

How deep it goes
Defines a runnable table with typed columns and demonstrates inspection, but leaves higher-level schemas and databases as separate abstractions.
Examples
Uses a trades table with identifiers, stock symbols, quantities, prices, and timestamps.
What it assumes
Assumes a running Postgres database and a connection, while introducing table structure through a concrete example.
What you can do after
Build it from scratch by defining a typed table, checking it with \d, and preparing it for generated sample rows.
How it connects
Connects tables with columns, data types, schemas, databases, INSERT, and generate_series.

Also explained in

Compare how 6 books explain CREATE TABLE statement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.