💻 Tech
In PostgreSQL, if you don’t specify the ordering via ORDER BY
, the ordering will be based on the plan types and order on the disk which may not be the order you’re expecting. For example, a common misconception is that the returned rows are based on their creation date; however, without the defined ordering, there’s no guarantee. This is particularly important if you have APIs that return array of items. If you don’t provide ordering on the SQL query, potential impacts can be random ordering shown on the UI or randomly failing unit test.
Reference: