Re: Missing numbers - Mailing list pgsql-general

From Harald Fuchs
Subject Re: Missing numbers
Date
Msg-id pu64wzjr6r.fsf@srv.protecting.net
Whole thread Raw
In response to Missing numbers  (josue <josue@lamundial.hn>)
Responses Re: Missing numbers
List pgsql-general
In article <429C7B9B.1040705@lamundial.hn>,
josue <josue@lamundial.hn> writes:

> Hello list,
> I need to track down the missing check numbers in a serie, table
> contains a column for check numbers and series like this:


> dbalm=# select doc_numero,doc_ckseriesfk from bdocs where doc_cta=1
> dbalm-# and doc_tipo='CHE' order by doc_numero;
>   doc_numero | doc_ckseriesfk
> ------------+----------------
>   19200      |         856938
>   19201      |         856938
>   19215      |         856938
>   19216      |         856938
>   19219      |         856938

> Missing numbers are:
> from 19202 to 19214 and 19217,19218


> Does anyone knows a way to get that done in SQL or plpgsql, thanks in
> advance

You could use something like that:

SELECT g.num
FROM generate_series ((SELECT min(doc_numero) FROM bdocs),
                      (SELECT max(doc_numero) FROM bdocs)) AS g(num)
LEFT JOIN bdocs ON bdocs.doc_numero = g.num
WHERE bdocs.doc_numero IS NULL

pgsql-general by date:

Previous
From: Christopher Browne
Date:
Subject: Re: Accessing PostgreSQL from C++
Next
From: Scott Marlowe
Date:
Subject: Re: For Tom Lane