Ehab
Ehab

Reputation: 19

Different Default ordering between ORACLE and PostgreSQL

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?

Upvotes: 0

Views: 681

Answers (1)

user330315
user330315

Reputation:

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)

Upvotes: 1

Related Questions