Unix Technical Forum

how do I to generate a sequence Range or Set of integer constants

This is a discussion on how do I to generate a sequence Range or Set of integer constants within the pgsql Sql forums, part of the PostgreSQL category; --> dear SQL friends, What I want to do might be done differantly. Right now I can't think of another ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 04:08 PM
Stefan Becker
 
Posts: n/a
Default how do I to generate a sequence Range or Set of integer constants

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

Thanks,

Stefan Becker
--
email: stefan@yukonho.de
tel : +49 (0)6232-497631
http://www.yukonho.de

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 04:08 PM
A. Kretschmer
 
Posts: n/a
Default Re: how do I to generate a sequence Range or Set of integer constants

am Fri, dem 23.02.2007, um 19:25:35 +0100 mailte Stefan Becker folgendes:
> 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)


Perhaps you are searching for generate_series():

test=*# select generate_series(1,10);
generate_series
-----------------
1
2
3
4
5
6
7
8
9
10
(10 rows)


Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 04:08 PM
Scott Marlowe
 
Posts: n/a
Default Re: how do I to generate a sequence Range or Set of integerconstants

On Fri, 2007-02-23 at 12:25, 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


select * from generate_series(1,1000);


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 04:08 PM
Joe
 
Posts: n/a
Default Re: how do I to generate a sequence Range or Set of integerconstants

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


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com