Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id C97DE860809 for ; Tue, 24 Apr 2012 12:30:12 -0300 (ADT) Received: from etc.kandalaya.org ([83.143.86.98] helo=images.kandalaya.org) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SMhgv-0002SO-CJ for pgsql-sql@postgresql.org; Tue, 24 Apr 2012 15:30:12 +0000 Received: from mail.linux-delhi.org ([120.59.42.93]) by images.kandalaya.org (8.14.3/8.14.3/Debian-9) with ESMTP id q3OFTlbM014046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 Apr 2012 20:59:51 +0530 Received: from mail.linux-delhi.org (raju@localhost [127.0.0.1]) by mail.linux-delhi.org (8.14.4/8.14.4/Debian-2) with ESMTP id q3OFTe3D002920; Tue, 24 Apr 2012 20:59:40 +0530 From: "Raj Mathur (=?utf-8?b?4KSw4KS+4KSc?= =?utf-8?b?IOCkruCkvuCkpeClgeCksA==?=)" Reply-To: raju@linux-delhi.org Organization: Kandalaya To: pgsql-sql@postgresql.org Subject: Re: Simple way to get missing number Date: Tue, 24 Apr 2012 20:59:40 +0530 User-Agent: KMail/1.13.7 (Linux/3.2.0-2-686-pae; KDE/4.6.5; i686; ; ) Cc: Andreas Kretschmer References: <4F96B57E.8080306@encs.concordia.ca> <20120424143655.GA7501@tux> In-Reply-To: <20120424143655.GA7501@tux> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201204242059.40709.raju@linux-delhi.org> X-Spam-Status: No, score=-9.0 required=5.0 tests=AWL,BAYES_00, DNS_FROM_RFC_BOGUSMX, LOCAL_FROM_RAJU, RCVD_IN_PBL, RDNS_NONE autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on images.kandalaya.org X-Virus-Scanned: clamav-milter 0.95.2 at images.kandalaya.org X-Virus-Status: Clean X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/51 X-Sequence-Number: 36528 On Tuesday 24 Apr 2012, Andreas Kretschmer wrote: > 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) Nice one, but curious about how would this perform if the numbers in question extended into 7 figures or more? Regards, -- Raj -- Raj Mathur || raju@kandalaya.org || GPG: http://otheronepercent.blogspot.com || http://kandalaya.org || CC68 It is the mind that moves || http://schizoid.in || D17F