Automatic row numbering / sequence in view ?

Started by Arnaud Lesauvageover 19 years ago3 messagesgeneral
Jump to latest
#1Arnaud Lesauvage
thewild@freesurf.fr

Hi List !

I need to add a column to a view, which would contain an automatically
generated sequence.
An automatic row numbering would do the trick (I only need unique
numbers, that's all), but I don't even know how to achieve this.
Does anybody have a solution for this problem ?

Thanks a lot !
--
Arnaud

#2Merlin Moncure
mmoncure@gmail.com
In reply to: Arnaud Lesauvage (#1)
Re: Automatic row numbering / sequence in view ?

On 10/10/06, Arnaud Lesauvage <thewild@freesurf.fr> wrote:

Hi List !

I need to add a column to a view, which would contain an automatically
generated sequence.
An automatic row numbering would do the trick (I only need unique
numbers, that's all), but I don't even know how to achieve this.
Does anybody have a solution for this problem ?

sure a sequence works. try this:

create sequence foo;

create view foobar as select *, nextval('foo') from bar;

If your query is complex, i would consider it to be good style to push
the real view into a subquery, such as:

select q.*, nextval('foo') from
(
[complex query here]
) q;

merlin

#3Arnaud Lesauvage
thewild@freesurf.fr
In reply to: Merlin Moncure (#2)
Re: Automatic row numbering / sequence in view ?

Merlin Moncure a �crit :

On 10/10/06, Arnaud Lesauvage <thewild@freesurf.fr> wrote:

Hi List !

I need to add a column to a view, which would contain an automatically
generated sequence.
An automatic row numbering would do the trick (I only need unique
numbers, that's all), but I don't even know how to achieve this.
Does anybody have a solution for this problem ?

sure a sequence works. try this:

create sequence foo;

create view foobar as select *, nextval('foo') from bar;

If your query is complex, i would consider it to be good style to push
the real view into a subquery, such as:

select q.*, nextval('foo') from
(
[complex query here]
) q;

merlin

How, great !
I did not know that way to use a sequence ! Still learning ! ;)
The query is quite complex indeed, so I will try with a subquery !
Thanks a lot Merlin !

--
Arnaud