From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: how to get row number in select query
Date: Thu, 27 Jan 2011 16:30:02 +0100
Message-ID: <ihs31q$1lm$1@dough.gmane.org> (raw)
In-Reply-To: <4D418D62.4010906@techbaza.pl>
References: <4D4047C1.5030208@encs.concordia.ca>
<D25246ED495942DD8E5777F5F9439DD0@marktestcr.marktest.pt>
<4D4181E9.2000305@encs.concordia.ca>
<090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt>
<4D418D62.4010906@techbaza.pl>
Piotr Czekalski, 27.01.2011 16:21:
> Gentelmen,
>
> I follow this thread and I don't exactly get an idea of yours, but
> isn't is as simple as (example: table "web.files" contains one column
> named "fileurl" ):
>
> select row_number() over(), X.fileurl from (select fileurl from
> web.files order by fileurl) X
>
> The only disadvantage is that if you do want to order resultset you
> have to use "select from select" as numbers are added before order
> which may cause some performance troubles.
>
You can get the row_number() without using the sub-select and without ordering the whole result as you can specify the order in the over() clause:
select fileurl
row_number() over (order by fileurl)
from web.files
Regards
Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: how to get row number in select query
In-Reply-To: <ihs31q$1lm$1@dough.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox