Lakebase Postgres is standard Postgres, so you create tables with standard CREATE TABLE syntax. Run the statement from the Neon SQL Editor in the Console, from psql, or through any application driver, and pick column types and constraints the same way you would on any Postgres server. For anything beyond a quick experiment, use a migration tool so your schema lives in version control.

Create a table

This example uses common Postgres types and constraints:

CREATE TABLE users (
  id           BIGSERIAL PRIMARY KEY,
  email        TEXT NOT NULL UNIQUE,
  display_name TEXT,
  is_active    BOOLEAN NOT NULL DEFAULT TRUE,
  metadata     JSONB NOT NULL DEFAULT '{}'::jsonb,
  created_at   TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at   TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE posts (
  id         BIGSERIAL PRIMARY KEY,
  user_id    BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  title      TEXT NOT NULL,
  body       TEXT,
  published  BOOLEAN NOT NULL DEFAULT FALSE,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX posts_user_id_idx ON posts (user_id);

Why these choices:

  • BIGSERIAL gives you an auto-incrementing 64-bit primary key. BIGINT GENERATED ALWAYS AS IDENTITY is the SQL-standard alternative and the better default for new schemas.
  • Use TEXT instead of VARCHAR(n) unless you need a length limit. Postgres stores both the same way.
  • TIMESTAMPTZ (timestamp with time zone) is almost always the right time type.
  • JSONB lets you store and index JSON. Use it for flexible attributes, and use regular columns for anything you query often.
  • REFERENCES adds a foreign key. Postgres doesn't index the referencing column for you, so add an index on it yourself, as the example does for posts.user_id.

Where to run it

  1. Open the Neon Console and select your project.
  2. Select Postgres database > SQL Editor.
  3. Select a branch and database.
  4. Paste the CREATE TABLE statement and click Run.

The SQL Editor also supports meta-commands like \dt (list tables) and \d users (describe a table). See Meta-commands.

Use a migration tool for real schemas

Ad-hoc CREATE TABLE is fine for prototyping. Once a schema needs to change over time, use a migration tool such as Drizzle, Prisma Migrate, Alembic, dbmate, Flyway, or sqlx. Migrations keep your schema in version control and apply the same changes in every environment. They also fit Neon's branching workflow: you can run a migration on a branch before you run it on production.

Connect Neon to your ORM

Step-by-step guides for Drizzle, Prisma, SQLAlchemy, and more.