PostgreSQL Best Practices

Chapter 1 · Practice 5 of 5

Use lowercase snake_case names and avoid quoted identifiers

From Schema design and data types

Why it matters

PostgreSQL folds unquoted names to lowercase. If an ORM creates a table called "UserAccounts" with quotes, every hand-written query must quote it exactly, forever. Lowercase snake_case names avoid that trap.

Pick your conventions once and write them down:

  • Plural or singular table names, but not both
  • _id suffixes for foreign keys, such as user_id
  • _at suffixes for timestamps, such as created_at
  • Explicit names for constraints and indexes, such as orders_user_id_idx

Explicit names keep migration diffs and error messages readable, instead of showing generated names nobody recognises.

A quick check that your conventions work: you should be able to guess a table's foreign key and index names without looking them up.

Do

  • Name foreign keys user_id, timestamps created_at
  • Name indexes like orders_user_id_idx
  • Configure your ORM to emit snake_case