The others are real data with meaning so far as your system is concerned, not actually surrogate keys, and should be named in a way that describes their content or use. If you effectively store multiple surrogate keys due to integrating with another systems that use something else, your internal identifier, is id. Of course this can't be perfect, I would avoid uuid as I know it is a type name in Postgres but devs who have only ever use SQL Server up to this point might not know that as it isn't a reserved word (or even a type name) there, and I might well use words that are not portable elsewhere similarly. This is a point against calling them uuid if the main point for calling them id is not enough. ) that could be a keyword so need escaping. You can't do arithmetic on it³ but the engine doesn't see it as any different to a bigger BIGINT being used as a key.Īnother general thing is that I try to avoid any name (for a column, table, function, procedure. In fact what you have with a UUID, unless you have had a brain-fart and stored them as strings¹, is effectively a large integer. All you should care about at that point is that it is a value that identifies something, so I stick with calling them ID⁰. You shouldn't ascribe meaning to your surrogate keys beyond the fact that they are a unique identifier for each row, as such it doesn't matter what format it takes from the point of view of your schema design. Indeed my question is: How would you call your UUID-typed surrogate keys and why? If you would brighten up my confusion with some solid bike-shedding, I would be much obliged. 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. 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. Id UUID PRIMARY KEY DEFAULT public.gen_random.uuid(), "uuid" UUID PRIMARY KEY DEFAULT public.gen_random.uuid(),Ī straight-forward alternative seems to be to instead call these columns id: CREATE TABLE thingie ( 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 ( However, this confronts me with a very consequential choice. I'm working on a database design that extensively uses UUIDs for PRIMARY KEYs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |