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:
SELECT i FROM t_user RIGHT JOIN generate_series(0,1000) as i ON (c_id=i)
WHERE c_id is null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With