问题
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
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