Ids the database makes, and keys of two columns

Step 1 of 110%

Concept · step 1 of 11

Let the database make the id

Writing ids by hand means the application has to know which one is next. An identity column makes the database do it.

  • `GENERATED ALWAYS AS IDENTITY` gives each new row the next number, without being asked..
  • ALWAYS means the application cannot supply its own. the database owns the column.
  • Numbers come from a sequence and are never handed out twice, even when an insert fails..
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY
Ada and Linus were inserted with only a name, and got 1 and 2. The ID badge on the board marks a column the database fills in.
PostgreSQL docs: CREATE TABLE, identity columns and PRIMARY KEY ↗

Starting Postgres in your browser

About 5 MB the first time, cached after that.

PostgreSQL running in your browser