Postgres Table Naming
Why do I prefer naming tables in postgres in the singular?
Some people treat tables as collections of rows. That’s not a bad approach — it’s perfectly logical, and it explains the naming style that uses the plural.
Others name tables in the singular and offer arguments like:
- entities with awkward plural forms are hard to translate; for instance, if the entity is called
Person, the table would bepersons, but the correct plural ispeople; - from this typically follows the obvious conclusion about how it makes
ORMwork simpler, and the explanation that this is how we try to talk to the system in an object-oriented language.
All of these arguments, in my view, are fairly weak.
Here’s the thing: Postgres is an object-relational DBMS. And every table in it is, in fact, a data type definition.
Take a look:
create table person
(
name text,
surname text
);
select ($$(John,Doe)$$::person).name;
Effectively, when you create a table, you’re defining a data type. You don’t use the plural to name your entity classes, do you? It’s the same idea here.
Of course, naming style is always the team’s call, and I’m not trying to impose my “correct” style on anyone.
When making the call, though, it’s much more engineering-grade and mature to rely on a fundamental explanation of your view.