Re: obtaining row number of select

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Keith Keller" <kkeller(at)speakeasy(dot)net>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: obtaining row number of select
Date: 2002-02-19 01:26:19
Message-ID: GNELIHDDFBOCMGBFGEFOGEHCCBAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> So I'm trying to generate a pseudo-serial number of a select
> statement on the fly, and I want to do so within the select
> statement. I could do this programmatically, but I wish to
> use the select statement so that I can use it in creating a
> view.
>
> So, I would like to do something like so:
>
> select serial(),* from mytable order by 1;
>
> But of course that won't work. :) Is there any way to
> autovivify a serial-like column for a select statement?
> (I've scoured the docs, and still can't find an answer.)

What about:

create sequence "myseq";
create view "myview" as select nextval('myseq'), * from mytable order by 1;

I tried this myself and every time I select from it, the sequence value is
incremented.

Chris

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rob 2002-02-19 05:54:08 maximum of sums
Previous Message Tom Lane 2002-02-18 21:04:46 Re: Why is my index not used