Finding 'holes'

Поиск
Список
Период
Сортировка
От Magnus Hagander
Тема Finding 'holes'
Дата
Msg-id 51F537775B63D0119D8D00805FBEB256CE495C@venture.edu.sollentuna.se
обсуждение исходный текст
Список pgsql-sql
Hi!

I need (well, not really need, but want to) a query that can give me the
"holes" in a sequence.
For example, I have a table which contains
id        data
--        ----
1        xxx
2        yyy
4        zzz
6        ...

I would then like a query that can return the values 3 and 5, since
those are the ones not existing in the table.
I guess I could create a table which contains all the values 1..max(id)
and then do a
SELECT id FROM all_ids WHERE id NOT IN (SELECT id FROM datatable)

but I would really like to make it without the need to create such a
table (which will in time be very large and unnecessary).

Does anybody know of a way to do this?

//Magnus

В списке pgsql-sql по дате отправления:

Предыдущее
От: Rachel Kay Street
Дата:
Сообщение: SQL Syntax: char to varchar type conversion(s)
Следующее
От: Natalino Picone
Дата:
Сообщение: Postgres Database Grows