Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 1C725145EA46 for ; Tue, 24 Apr 2012 11:37:13 -0300 (ADT) Received: from mailout01.ims-firmen.de ([213.174.32.96]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SMgrf-0001Uf-NA for pgsql-sql@postgresql.org; Tue, 24 Apr 2012 14:37:12 +0000 Received: from mailin04.ims-firmen.de ([192.168.1.144]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1SMgrQ-0000du-UD for pgsql-sql@postgresql.org; Tue, 24 Apr 2012 16:36:57 +0200 Received: from [87.170.185.237] (helo=a-kretschmer.de) by mailin04.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1SMgpy-0005yQ-2c for pgsql-sql@postgresql.org; Tue, 24 Apr 2012 16:35:26 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1SMgrP-00021D-KI for pgsql-sql@postgresql.org; Tue, 24 Apr 2012 16:36:55 +0200 Date: Tue, 24 Apr 2012 16:36:55 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Simple way to get missing number Message-ID: <20120424143655.GA7501@tux> References: <4F96B57E.8080306@encs.concordia.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4F96B57E.8080306@encs.concordia.ca> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/49 X-Sequence-Number: 36526 Emi Lu wrote: > Good morning, > > May I know is there a simple sql command which could return missing > numbers please? > > For example, > > t1(id integer) > > values= 1, 2, 3 .... 5000000 > > select miss_num(id) > from t1 ; something like ,----[ code ] | test=# select * from emi_lu ; | i | --- | 1 | 2 | 3 | 5 | 6 | 8 | 9 | (7 rows) | | Time: 0,246 ms | test=*# select * from generate_Series(1,10) s left join emi_lu on | (s=emi_lu.i) where i is null; | s | i | ----+--- | 4 | | 7 | | 10 | | (3 rows) `---- this? Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°