> Now, sometimes a table has a natural primary key, for example the social security number of a country’s citizens. You know, you think that, but it's never that simple. The field was added incorrectly and nobody noticed until the value is in countless tables that you now need to simultaneously update or the value is something that's supposed to be semi-secret, so now a low level support staff can't reference the row…
In Spain each person has a unique ID number assigned at birth. The numbers for newborns are geographically pre-distributed to guarantee uniqueness despite delay in paperwork. It is universally accepted that this ID "number" (it actually has one letter too) is all you need to identify yourself, ever. Except that I knew a coworker who had a duplicate ID. An extremely rare event, they messed up the pre-assignment and th…
UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
141–150 of 182 posts
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#142Earlier quoted context omitted.
In the Netherlands SSNs are not unique, they handed out some duplicate ones back in the day. So not great as a primary key. Besides, I think using them as primary keys is illegal anyway.
Huh? How does sign-in work for people with duplicate ID’s?
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#143A little late to comment here. But for database IDs, I have found that Instagram's technique to generate IDs works very well: https://instagram-engineering.com/sharding-ids-at-instagram-... They are not serially incrementing but still sortable. Thus prevent index fragmentation issues observed with UUIDS. Are 8 bytes in length. So index size is smaller compared to UUIDs. So you get all benefits of serial IDs but they…
I don't see how that's true. From reading the article you linked, you only need a valid shard ID (which you can extract from known IDs), the millisecond (which is guessable) and a 10-bit sequence (which you can easily brute-force).
(And that's completely fine if their security model doesn't require unguessable IDs.)
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#144Earlier quoted context omitted.
A vote here against integer/serial PKs, not only because they leak information, but also because they can result in incorrect joins. IME it's much more often I've quickly made a table with a serial PK and later wished it were uuid; just about never made a uuid and later wished for the compactness or natural clustering of bigint. Maybe for a table of millions and millions of time-ordered events.
Note I said "internal use". But how can primary keys result in incorrect joins? Unless you're changing a foreign key, joins will always be correct. Unless I'm doing something wrong in the last 30 years of using SQL.
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#145Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#146I feel the whole debate is overkill: 99% of businesses/systems will never have so much data that they NEED to use uuid's. I personally don't like using integers for keys either as I've been burnt by them before. I also doubt any software I build today or have built in the last 10 years will be used 100 years from now. Recently I built a new system (typical business-type backend) and forced to use sqlite + C# + dapper…
> Recently I built a new system (typical business-type backend) and forced to use sqlite + C# + dapper. Using this combination I cannot use guid/uuid as dapper cannot properly map it back to c# from sqlite Are you sure about this? This is pretty poor of a well known solution in the ORM world, SQLite or not. If you were going for sortability/understandability then I understand slapping your own together, but why not g…
But of a rabbit hole: https://github.com/DapperLib/Dapper/pull/1082
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#147Earlier quoted context omitted.
We'll have to agree to disagree. Systems like the ones I described are a hell of a lot easier to build on long term while maintaining those invariants.
How is that easier to maintain than literally just having a UUID primary key? I feel like we must be talking about different use cases
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#148UUIDs are great when you use the id "publicly" but using an incremental value would be too revealing for different reasons. So it's good to know that performances are not bad.
I’ve stuck with incremental values internally but use Hashid to convert them when exposed publicly. Seems to work well.
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#149Earlier quoted context omitted.
> Recently I built a new system (typical business-type backend) and forced to use sqlite + C# + dapper. Using this combination I cannot use guid/uuid as dapper cannot properly map it back to c# from sqlite Are you sure about this? This is pretty poor of a well known solution in the ORM world, SQLite or not. If you were going for sortability/understandability then I understand slapping your own together, but why not g…
The problem is when reading the data back with Dapper (writing works fine) and it has to parse the guid stored in sqlite back into a .net Guid. Thus I resorted to making the column type text and ToString() all the Guid's before writing, but that's pretty gross. With a normal string field, sqlite can set it as primary key, make unique indexes on it, use it as foreign keys. Thus my attempt to use my own generator the g…
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#150Earlier quoted context omitted.
> > Now, sometimes a table has a natural primary key, for example the social security number of a country’s citizens. > You know, you think that, but it's never that simple. It’s that simple if you’re the Social Security Administration and its a table of Social Security Accounts, not people. Other than that, using SSNs as a primary key is just plain wrong.
Maybe using them as passwords is what's wrong.
Or if you're expanding to countries whose SSNs clash with each other?
SSN as PK is wrong regardless of whether you're doing SSN as password.