How to get the position of each record in a SELECT statement

From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: How to get the position of each record in a SELECT statement
Date: 2016-10-07 17:20:29
Message-ID: CAAY=A7_PdEeLWtQev0ZDnky9b4PzU1QHn0JYK4S5fS4qXG3kig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Let´s say that I have the following simple SELECT statement:

SELECT first, id FROM customers ORDER BY first

This would result in something like this:
Charles C1001
John A3021
Kevin F2016
Paul N4312
Steve J0087

Is it possible to include a "field" in the SELECT such that it represents
the position of each record?
For example, I need to get a result like this:

1 Charles C1001
2 John A3021
3 Kevin F2016
4 Paul N4312
5 Steve J0087

Respectfully,
Jorge Maldonado

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stephen Tahmosh 2016-10-07 17:31:27 Re: How to get the position of each record in a SELECT statement
Previous Message Adrian Klaver 2016-10-07 13:19:34 Re: Large Objects