Sample Header Ad - 728x90

Should I call my UUID primary key column ID or not?

20 votes
2 answers
12029 views
I'm working on a database design that extensively uses UUIDs for PRIMARY KEYs. However, this confronts me with a very consequential choice. How do I name these columns? I would call them uuid, except that, UUID being an identifier, I then have to quote the field name everywhere:
CREATE TABLE thingie (
  "uuid" UUID PRIMARY KEY DEFAULT public.gen_random.uuid(),
  foo VARCHAR,
  bar VARCHAR,
);
A straight-forward alternative seems to be to instead call these columns id:
CREATE TABLE thingie (
  id UUID PRIMARY KEY DEFAULT public.gen_random.uuid(),
  foo VARCHAR,
  bar VARCHAR,
);
That way, I don't have the column name, and semantically I can argue that a UUID is indeed a sort of ID; in a Venn diagram, the UUID circle would be placed wholly in the ID circle. *However*, I (and I am sure many others with) have grown so accustomed to associating id with an auto-incrementing INTEGER column that I'm afraid to break some sort of unspoken rule by calling these IDs ids. If you would brighten up my confusion with some solid bike-shedding, I would be much obliged. Indeed my question is: **How would _you_ call your UUID-typed surrogate keys and why?**
Asked by BigSmoke (814 rep)
Apr 24, 2022, 09:33 AM
Last activity: Apr 26, 2022, 09:31 AM