C
C#2y ago
honk

❔ Auto incremented Id not sequential

Hello, I have an auto increment on an Id(integer) column on a database, however values are not sequential. The gaps aren't caused by deletion, as we have no functionality for it on our website( unless someone is intentionally deleting them by hand :p ). For example, these are the Id's for the first 22 records from the db:
34
67
100
133
134
135
166
199
232
265
298
331
364
397
430
463
496
529
562
595
628
34
67
100
133
134
135
166
199
232
265
298
331
364
397
430
463
496
529
562
595
628
Is this something to worry about? I'm using EF core.
8 Replies
honk
honk2y ago
Just realized most of these are incrementing by 33, however there are a few exceptions catthinking
Pobiega
Pobiega2y ago
What database software? Is it perhaps using HiLo? in MSSQL, its possible to tell a table to use a certain sequence to get its IDs from, and a sequence could easily be configured to have an increment of 33
honk
honk2y ago
I'm using Postgres db and looking at the sequence, nothing seems to be out of the ordinary( it was auto generated by ef). The issue seems to be with this table only as well.
Pobiega
Pobiega2y ago
But there is a sequence specifically for this table?
honk
honk2y ago
Yes.
create sequence "MyTable_Id_seq";

alter sequence "MyTable_Id_seq" owner to postgres;

alter sequence "MyTable_Id_seq" owned by "MyTable"."Id";
create sequence "MyTable_Id_seq";

alter sequence "MyTable_Id_seq" owner to postgres;

alter sequence "MyTable_Id_seq" owned by "MyTable"."Id";
Pobiega
Pobiega2y ago
Alright, my postgres isn't amazing, but if you were to check currval and nextval on that, (use a transaction and roll it back!), what do you get https://www.postgresql.org/docs/current/functions-sequence.html
honk
honk2y ago
Sorry for the late response, discord isn't showing me notifications for some reason. Nextval incremented the value by 1 each time I called it
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.