Re: [GENERAL] need ``row number``

Поиск
Список
Период
Сортировка
Искать
От
Tom Lane
Тема
Re: [GENERAL] need ``row number``
Дата
Msg-id
21339.1096035613@sss.pgh.pa.us
Ответ на
Re: need ``row number`` (Karsten Hilbert)
Список
Дерево обсуждения
Re: [GENERAL] need ``row number`` Karsten Hilbert <Karsten.Hilbert@gmx.net>
Re: [GENERAL] need ``row number`` Tom Lane <tgl@sss.pgh.pa.us>
Re: [GENERAL] need ``row number`` Greg Stark <gsstark@mit.edu>
Karsten Hilbert  writes:
> I am not convinced I'll need a SRF. I am not trying to
> calculate something that isn't there yet. I am just trying to
> join two views appropriately. I might have to employ some
> variant of Celko's integer helper table but I'm not sure how
> to proceed.

A fairly common hack for this is to use a sequence:

	create temp sequence tseq;
	select nextval('tseq'), * from (select .... order by ...) ss;

Note you must do any desired ORDER BY inside the subselect.  If it's
outside then it happens after computation of the row numbers, which
is exactly not what you want.

The major limitation of this is that you need to do some auxiliary
operations to create or reset the semaphore before each query.

There are some related hacks in the archives that use PL functions
with private persistent state, instead of a sequence object.

			regards, tom lane
В списке pgsql-sql по дате отправления
От: Jennifer Lee
Дата:
Сообщение: select column by position
От: Oliver Nolden
Дата:
Сообщение: How to insert values in bytea?
FAQ