Re: Automatic row numbering / sequence in view ?

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Arnaud Lesauvage" <thewild(at)freesurf(dot)fr>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Automatic row numbering / sequence in view ?
Date: 2006-10-10 14:49:31
Message-ID: b42b73150610100749j366f34aeje4c24381e08d1fb1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/10/06, Arnaud Lesauvage <thewild(at)freesurf(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arnaud Lesauvage 2006-10-10 14:51:39 Re: Automatic row numbering / sequence in view ?
Previous Message Arnaud Lesauvage 2006-10-10 14:42:37 Automatic row numbering / sequence in view ?