Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E04B79FC2D3 for ; Fri, 23 Feb 2007 15:35:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 69333-04 for ; Fri, 23 Feb 2007 15:35:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48]) by postgresql.org (Postfix) with ESMTP id 0564D9FB528 for ; Fri, 23 Feb 2007 15:35:39 -0400 (AST) Received: from [192.168.7.5] ([71.101.14.120]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JDX00JSBL3DL598@vms048.mailsrvcs.net> for pgsql-sql@postgresql.org; Fri, 23 Feb 2007 13:35:39 -0600 (CST) Date: Fri, 23 Feb 2007 14:36:17 -0500 From: Joe Subject: Re: how do I to generate a sequence Range or Set of integer constants In-reply-to: <200702231925.35411.pgsql@yukonho.de> To: Stefan Becker Cc: pgsql-sql@postgresql.org Message-id: <1172259377.736.9.camel@pampa> Organization: Freedom Circle, LLC MIME-version: 1.0 X-Mailer: Evolution 2.8.3 FreeBSD GNOME Team Port Content-type: text/plain Content-transfer-encoding: 7bit References: <200702231925.35411.pgsql@yukonho.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/241 X-Sequence-Number: 27575 On Fri, 2007-02-23 at 19:25 +0100, Stefan Becker wrote: > dear SQL friends, > > What I want to do might be done differantly. Right now I can't > think of another solution other than a select statement > > I would like to create a sequence range of integer constants. Join > this sequence against a ID Range in a database and look for missing > Id's. > > Another application for this would be to simply populate a database with > say 1000..9999 Records.... > > Now: Is there a syntax that allows for the following..... > > create table XX (id int); > insert into XX (select xx from "1 to 1000" of integers) > > or... > > select IntSeq.MissingValues, x.UniqIntId,x.A,x.B,x.C, > from MyDataTable x > left outer join > ( > select MissingValues from "1 to 1000" of integers > ) IntSeq on MissingValues=x.UniqIntId > > > I'm hoping that someone has done this and might be able to > point to some function or methode to do this Maybe something like this will help: SELECT id FROM generate_series(1, (SELECT last_value FROM id_seq)) AS s(id) EXCEPT SELECT UniqIntId FROM MyDataTable ORDER BY id; The id_seq is the sequence on your ID column, assuming it has one, or you can replace the (SELECT ... FROM id_seq) by 1000. Joe