dbTalk Databases Forums  

dynamic row sequence

comp.databases.informix comp.databases.informix


Discuss dynamic row sequence in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Cesar Inacio Martins
 
Posts: n/a

Default dynamic row sequence - 09-10-2010 , 01:45 PM






Hi,

I need a resource , what is common in any other database...

Return the sequence # of the rows returned from select, something like:

select func_rownu(), name from users
where state = 'NY';
1 john
2 katty
3 mike
4 nattan
and so on...

So , what I need is this "virtual serial/sequence" of the rows returned...
Anyone already do this ?

Cesar

Reply With Quote
  #2  
Old   
Holger de Wall
 
Posts: n/a

Default Re: dynamic row sequence - 09-10-2010 , 02:27 PM






Hi,

"... In Dynamic Server, you can use the rowid column that is associated
with a table row as a property of the row. ..."
from
http://publib.boulder.ibm.com/infoce...archWord=rowid

select ROWID, name from users where state = 'NY';

--
Holger

Am 10.09.2010 20:45, schrieb Cesar Inacio Martins:
Quote:
Hi,

I need a resource , what is common in any other database...

Return the sequence # of the rows returned from select, something like:

select func_rownu(), name from users
where state = 'NY';
1 john
2 katty
3 mike
4 nattan
and so on...

So , what I need is this "virtual serial/sequence" of the rows returned...
Anyone already do this ?

Cesar






_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
  #3  
Old   
Cesar Inacio Martins
 
Posts: n/a

Default Re: dynamic row sequence - 09-10-2010 , 07:28 PM



Hi Holger,
Thanks for your answer, but isn't this what I looking.
Row id isn't sequencial numbers.. don't solve my problem...

Cesar

--- Em sex, 10/9/10, Holger de Wall <holger (AT) dewall-net (DOT) de> escreveu:

De: Holger de Wall <holger (AT) dewall-net (DOT) de>
Assunto: Re: dynamic row sequence
Para: informix-list (AT) iiug (DOT) org
Data: Sexta-feira, 10 de Setembro de 2010, 16:27

Hi,

"... In Dynamic Server, you can use the rowid column that is associated
with a table row as a property of the row. ..."
from
http://publib.boulder.ibm.com/infoce...archWord=rowid

select ROWID, name from users where state = 'NY';

--
Holger

Am 10.09.2010 20:45, schrieb Cesar Inacio Martins:
Quote:
* Hi,

I need a resource , what is common in any other database...

Return the sequence # of the rows returned from select, something like:

select func_rownu(), name from users
where state = 'NY';
1 john
2 katty
3 mike
4 nattan
and so on...

So , what I need is this "virtual serial/sequence" of the rows returned....
Anyone already do this ?

Cesar


*



_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list
_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
  #4  
Old   
Doug Lawry
 
Posts: n/a

Default Re: dynamic row sequence - 09-11-2010 , 07:04 AM



Try this:

CREATE FUNCTION spl_sequence
(start_value INTEGER DEFAULT NULL)
RETURNING INTEGER;

-- Doug Lawry, comp.databases.informix, 11/09/2010
-- Usage: SELECT spl_sequence(), * FROM ...
-- Optional: EXECUTE FUNCTION spl_sequence(?)
-- Bugs: GROUP BY or ORDER BY unless indexed

DEFINE GLOBAL spl_sequence INTEGER DEFAULT 1;

IF start_value IS NOT NULL THEN
LET spl_sequence = start_value - 1;
RETURN NULL;
ELSE
LET spl_sequence = spl_sequence + 1;
RETURN spl_sequence;
END IF

END FUNCTION;

Reply With Quote
  #5  
Old   
Doug Lawry
 
Posts: n/a

Default Re: dynamic row sequence - 09-11-2010 , 07:08 AM



Wih global default corrected:

CREATE FUNCTION spl_sequence
(start_value INTEGER DEFAULT NULL)
RETURNING INTEGER;

-- Doug Lawry, comp.databases.informix, 11/09/2010
-- Usage: SELECT spl_sequence(), * FROM ...
-- Optional: EXECUTE FUNCTION spl_sequence(?)
-- Bugs: GROUP BY or ORDER BY unless indexed

DEFINE GLOBAL spl_sequence INTEGER DEFAULT 0;

IF start_value IS NOT NULL THEN
LET spl_sequence = start_value - 1;
RETURN NULL;
ELSE
LET spl_sequence = spl_sequence + 1;
RETURN spl_sequence;
END IF

END FUNCTION;

Reply With Quote
  #6  
Old   
Cesar Inacio Martins
 
Posts: n/a

Default Re: dynamic row sequence - 09-11-2010 , 05:39 PM



Thanks Doug,
But what I trying avoid is the requirement of manually start the sequence....
this way don't work for me..

--- Em sáb, 11/9/10, Doug Lawry <lawry (AT) nildram (DOT) co.uk> escreveu:

De: Doug Lawry <lawry (AT) nildram (DOT) co.uk>
Assunto: Re: dynamic row sequence
Para: informix-list (AT) iiug (DOT) org
Data: Sábado, 11 de Setembro de 2010, 9:04

Try this:

CREATE FUNCTION spl_sequence
* * (start_value INTEGER DEFAULT NULL)
* * RETURNING INTEGER;

* * -- Doug Lawry, comp.databases.informix, 11/09/2010
* * -- Usage: SELECT spl_sequence(), * FROM ...
* * -- Optional: EXECUTE FUNCTION spl_sequence(?)
* * -- Bugs: GROUP BY or ORDER BY unless indexed

* * DEFINE GLOBAL spl_sequence INTEGER DEFAULT 1;

* * IF start_value IS NOT NULL THEN
* * * * LET spl_sequence = start_value - 1;
* * * * RETURN NULL;
* * ELSE
* * * * LET spl_sequence = spl_sequence + 1;
* * * * RETURN spl_sequence;
* * END IF

END FUNCTION;
_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.