I have a table t_user:
CREATE TABLE t_user
(
c_id bigint NOT NULL,
c_lastname character varying(255)
)
The table is not using any sequences to generate the IDs, instead these are calculated outside of Postgres (don’t ask, and don’t care about possible problems that this can cause).
Now there are some “holes” in a range from 0 to 1000 that I need to know of and fill up.
Is it possible to formulate a Postgres query that gives me all unused IDs in that table in a range from 0 to 1000?
It’s a classic case of using generate_series and an outer join: