zonkyio / embedded-postgres

Java embedded PostgreSQL component for testing
Apache License 2.0
352 stars 47 forks source link

Order not maintained on Zonky #74

Closed mcherb closed 3 years ago

mcherb commented 3 years ago

I have this select :

select * from unnest(array[
    'R:335901068',
    'A:-659857413',
    'R:-801583335',
    'A:-197178211'
    ])
order by 1

In my local postgres instance (from docker image 9.6) I get this result :

Local

A:-197178211
A:-659857413
R:335901068
R:-801583335

But Zonky instance returns me the following result :

A:-197178211
A:-659857413
R:-801583335
R:335901068

When executed SHOW ALL on both of instances, I've found a difference in locale informations. So I've added the following configuration to the zonky instance.

.setLocaleConfig("locale", "en_US.UTF-8")
.setLocaleConfig("lc-collate", "en_US.UTF-8")
.setLocaleConfig("lc-ctype", "en_US.UTF-8")
.setLocaleConfig("lc-messages", "en_US.UTF-8")
.setLocaleConfig("lc-monetary", "en_US.UTF-8")
.setLocaleConfig("lc-numeric", "en_US.UTF-8")
.setLocaleConfig("lc-time", "en_US.UTF-8")

The result is always different !

Is there any this else to change ?

Config io.zonky.test:embedded-postgres:1.2.10 io.zonky.test.postgres:embedded-postgres-binaries-bom:9.6.15 (tried with 21 also)

MacOs Darwin myHost 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64

tomix26 commented 3 years ago

The order of the records in postgres can be system dependent. If you run postgres in a docker container it is running under linux kernel instead of mac os kernel, so the results might be sligthly different. The embedded postgres library itself does not affect the processing of database queries in any way. If you really need to have system independent queries, you have to upgrade to postgres 10+ and use ICU feature. You can find more information in the following article: https://www.2ndquadrant.com/en/blog/icu-support-postgresql-10