PostgreSQL reorders returned rows

I have a table with category names that contains identifiers (long), Name (varchar (50)), parentID (long) and showByDefault (boolean).

This table contains 554 entries. All ByDefaultValues ​​shown are false.
When I execute 'select id, name from categories', pg returns me all categories, by the customer by its identifier.
Then I update some rows of the table ("update categories set in ByDefault, where parentId = 1"), update OK.
Then, when I try to execute the first query that returns all the categories, they return in a very strange order.
I have no problem adding "order by", but since I use JPA to get these values, does anyone know what the problem is, or is there any way to fix this?

+5
source share
3 answers

. , SQL SELECT, undefined, ORDER BY. , , , , / , .

ORDER BY .

, .

, set , sequence .

+16

docs:

ORDER BY, . ORDER BY , , .

+9

Lines are returned in any physical order on disk; you can reorder them physically using the CLUSTERSQL command , but because of how Postgres works, they will become disordered as soon as you start changing lines.

What you do ORDER BYis the correct answer.

+2
source

All Articles