how to sort by line number in a query in postgres?

5

To populate the grid of a view I'm using the database, initially I put the table ID to be the index of the view, however when some record is deleted from the database the index does not become sequential.

    
asked by anonymous 16.11.2016 / 15:23

1 answer

3

So I understand you'd like to have a sequence of 1 to n not caring for the value of the id field.

I think it would look something like this:

SELECT
  row_number() OVER (ORDER BY id_grupo) AS ROWNUM,
  nome
FROM
  grupos;

I created a test fiddle:

link

    
17.11.2016 / 13:11