How to find values missing from a sequence? I want to find rows missing from a sequence of values in my table. For example, in this picture documentno 'YD4BC2006008' is missing.
I want to find the missing lines via c_order_id and documentno.
I tried this but it didn't return the expected result:
select * from
(SELECT distinct c_order_id, documentno,cast(right(documentno,3) as integer) as no
FROM adempiere.c_order
ORDER BY documentno, c_order_id) as f


In this example  many rows missing: from 'DGPOS2003030' to 'DGPOS2003068'.
How do I write a query to retrieve them?
One easy way is to generate a list of all potential documentnos and remove from that all the ones that exist:
select 'YD4BC' || generate_series(2006004, 2006015) as missing_documentno
except
select documentno from documents;