X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3059C52B86 for ; Wed, 13 Jul 2005 10:22:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25125-08 for ; Wed, 13 Jul 2005 13:22:40 +0000 (GMT) Received: from amanda.contactbda.com (ipn36372-e65122.cidr.lightship.net [216.204.66.226]) by svr1.postgresql.org (Postfix) with ESMTP id 4DA7252AD3 for ; Wed, 13 Jul 2005 10:22:31 -0300 (ADT) Received: from amanda.contactbda.com (amanda.contactbda.com [192.168.1.2]) by amanda.contactbda.com (8.12.11/8.12.11/Debian-3) with ESMTP id j6DDMWRC025678; Wed, 13 Jul 2005 09:22:32 -0400 From: "Jim Buttafuoco" To: Aaron Bingham , pgsql-sql@postgresql.org Reply-To: jim@contactbda.com Subject: Re: Generating a range of integers in a query Date: Wed, 13 Jul 2005 09:22:32 -0400 Message-Id: <20050713132129.M45696@contactbda.com> In-Reply-To: References: X-Mailer: Open WebMail 2.41 20040926 X-OriginatingIP: 192.168.1.1 (jim) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.052 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/110 X-Sequence-Number: 22088 I use the following function which returns a date series. You can modify it to return an int series instead create or replace function alldates(date,date) returns setof date as ' declare s alias for $1; e alias for $2; d date; begin d := s; while d <= e LOOP return next d; select d + \'1 day\'::interval into d; END LOOP; return null; end; ' LANGUAGE 'plpgsql' ; select * from alldates('2004-07-01','2004-08-10'); ---------- Original Message ----------- From: Aaron Bingham To: pgsql-sql@postgresql.org Sent: Wed, 13 Jul 2005 11:13:06 +0200 Subject: [SQL] Generating a range of integers in a query > Hello, > > I've got an interesting problem: I need to select all possible values > of an attribute that do /not/ occur in the database. > > This would be easy (in my case at least) if there were a way to > generate a table containing all integers between 1 and n, where n is > the result of a subquery. In my case, n will be at most a few > hundred. I would like to be able to generate this table as a > subquery. Any ideas? > > Thanks, > > -- > -------------------------------------------------------------------- > Aaron Bingham > Senior Software Engineer > Cenix BioScience GmbH > -------------------------------------------------------------------- > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq ------- End of Original Message -------