Skip to content
Advertisement

Different sort results between Oracle and Postgres with Special Characters

*Apologies as I know this question has been asked before, but tried the previously suggested approaches and none fixed my issue.

I am trying to compare a table found in two databases.

Unfortunately, the table does not have a primary key, so I am trying to order by the same column and compare that way.

When I sort the above table in Oracle, it sorts to:

However, when I perform the sort in Postgres, it sorts to:

This issue appears to be how the ^ character is sorted. Does anyone know a workaround so that both databases sort the information the same way?

Advertisement

Answer

Creating hash values and using them for ordering seems to be an option.

Test tables (Postgresql / Oracle)

enter image description here enter image description here

Query (Postgresql) – order by MD5 hash

Query (Oracle) – order by MD5 hash

If the MD5 is not good enough, you can also use SHA256, which will probably give you a different ordering, but the same order result for both Postgresql and Oracle. Examples on DBfiddle, for Postgresql 12 and Oracle 18c.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement