0

I found a really strange thing related to postgresql. Here is my query:

select * 
from "bids" 
  inner join "users" on "users"."id" = "bids"."userId" 
where "auctionId" = 151

And here is a result:

enter image description here

So, as you see, rows are sorted in descending order by id. If I add ordering in query:

select * 
from "bids" 
   inner join "users" on "users"."id" = "bids"."userId" 
where "auctionId" = 151 
order by "bids"."id" asc

I get a result:

enter image description here

It looks like one of database settings was set incorrectly, but I couldn't find it in google. Please, put your thoughts here, any help is welcome.

Thanks.

lutaev
  • 298
  • 1
  • 4
  • 20
  • 1
    I don't think any relational database engine ensures any particular order of rows unless you explicitly specify one in the query, what do you feel is "wrong" here? – Jcl Nov 27 '22 at 09:58
  • Rows in a relational database have no implied sort order. Unless you use an `ORDER BY` the database is free to return the rows in any order it likes. The ***only*** way to get a guaranteed sort order is to use `ORDER BY` –  Nov 27 '22 at 10:00

0 Answers0