I'm playing with:
DROP TABLE users CASCADE;
CREATE SEQUENCE users_id_seq MINVALUE 100;
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('users_id_seq') * 100 + 1,
...
);
ALTER SEQUENCE users_id_seq OWNED BY users.id;
DROP TABLE txns CASCADE;
CREATE SEQUENCE txns_seq MINVALUE 100;
CREATE TABLE txns (
id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('txns_seq') * 100 + 2,
...
);
ALTER SEQUENCE txns_seq OWNED BY txns.id;
...
To my mind, this has the following benefits:
- Each id is unique across the whole database, removing wrong-table errors.
- No id has a value of less than 10,000, removing confusion with most iteration counters.
- The containing table is easily learned from the last two digits of any id.
Disadvantages:
- We're wasting 99% of ids.
What other disadvantages haven't I considered?