Different Default ordering between ORACLE and PostgreSQL

…衆ロ難τιáo~ 提交于 2021-01-29 13:17:46

问题


I have a simple ORACLE Query which I should rewrite it to be run on postgresql with same output as below

 Select X,Y FROM table_name order by Y

in case of I have only the below data in the table

Here you are the difference between PG and oracle in ordering the data

Difference in output

Do you have idea why such this difference occurs?


回答1:


Different Default ordering

There is no such thing as "default ordering" - neither in Oracle nor in Postgres (or in any other relational database). Tables in a relational database represent un-ordered sets.

You are sorting on a column that contains the same value for both (all) rows. This is essentially the same as not sorting at all, because you have not defined any sort criteria to break those ties. Without an additional sort column the database is free to return the rows with the same sort value in any order it likes.

If you want the rows sorted by column x you need to include that column in the order by

select X,Y 
FROM table_name 
order by x,y;

or maybe you want order by y,x - it's not clear from your question (and the hardly readable screen shots)



来源:https://stackoverflow.com/questions/63687790/different-default-ordering-between-oracle-and-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!