Re: row numbering

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Marcin Inkielman <marn(at)wsisiz(dot)edu(dot)pl>
Cc: Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: row numbering
Date: 2000-05-10 21:24:46
Message-ID: Pine.LNX.4.21.0005102303220.30279-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marcin Inkielman writes:

> how may i easyly obtain row numbers in a query:

In the SQL data model, rows don't have numbers, because rows aren't
ordered -- a query may return the rows in any order. So if you are
building on that assumption you might have to rethink slightly.

If you need to number your records for some reason, say invoice numbers,
you can use a sequence:

create table my_tbl (
nr serial, -- creates implicit sequence
... more fields ...
);

Then you can select them like any other field. You say you had
unsatisfying results, would you care to explain why?

Lastly, there is the OID which every row gets automatically assigned by
the system. This is a unique number across the whole installation. You can
access it as
select oid, your, fields, here from table ...
like a regular column. The OID may be good enough to get some sort of
number on a row but be aware that it is wildly non-portable.

--
Peter Eisentraut Sernanders väg 10:115
peter_e(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2000-05-10 21:25:29 Re: [HACKERS] Re: Problems compiling version 7
Previous Message Alfred Perlstein 2000-05-10 21:14:58 Re: 6.5.3 -> 7.0 upgrade went smoothly, thanks