3 ms·
So.. are database IDs numbers? Because they sure are autoincrement integers in almost every DBMS. I always thought that was a mistake but it's practical.
by NelsonMinar 5y ago
So.. are database IDs numbers? Because they sure are autoincrement integers in almost every DBMS. I always thought that was a mistake but it's practical.
- Quekid5 5y agoYes, but as soon as they leave the realm of the DB itself, they (should) become opaque identifiers.
- masklinn 5y ago> So.. are database IDs numbers? No. > Because they sure are autoincrement integers in almost every DBMS. The autoincrement occurs before it's a database ID. The generator for database ids is a sequence, that has no bearing on the semantics of the database ids.
- mind-blight 5y agoIt's becoming pretty standard to use UUIDs over integers now. That provides more architectural flexibility
- marcosdumay 5y agoThey are absolutely not numbers. As many people already commented, it's reasonable to encode things as numbers as long as you keep in mind there's an encoding operation with it's possible flaws.
- kenjackson 5y agoHonestly that seems like a cop out.
- Spivak 5y agoI mean strings are numbers if you want to be that reductive. The “on-disk” representation of the thing is independent of its real type and properties. So sure, store a date in an “integer” but if you try to treat it like one instead of a bitfield you’ve made an error and if your storage isn’t wide enough to hold all dates that’s gonna be a PITA later.
- marcosdumay 5y agoThe usual habit of typing ids as integral numbers is incorrect, they are not numbers. But the problems it causes are well known and dealt with by what is broadly known as good practices. Is it better this way? (You can see the problems clashing with each other if you search for discussions about defaulting ids to 32 or 64 bits. So they are not completely solved, the practices are just good enough that things don't usually break on practice.) At the end of the day, all you have on a computer is a bitfield to mess around. You will always have to deal with encoding at some point.