-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Getting collations to work on Alpine using ICU #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Maybe setting some more environment variables like |
I've tried setting all the different LC_* variables to my desired locale to no avail. The key is in version 15 of Postgres. And the timing couldn't be better, because it's only like 3-4 days old.
So, as per docs on locales and locale providers, the solution is a simple one-liner for initializing your DB cluster with any desired icu collation: I first used my desired collation with Alpine with a simple custom Dockerfile:
Worked like a charm, so I skipped the need for a custom Dockerfile altogether and just passed that ENV in through the docker-compose.yml using the unmodified postgres:15-alpine image. Might I suggest updating the docs (Locale Customization) to include the solution for Alpine based images.
statement is not correct anymore. |
I need custom collations and would really prefer to use Alpine as a base.
I know about Musl (currently) only supporting C or POSIX locales so instead of using a libc as a provider, I tried using icu.
My sources:
I couldn't figure out, why the Docker image postgres:13-alpine doesn't contain all icu locales, because this line in its build source would have me believe it's included already. If anybody could explain that, that would be bonus points.
So I decide to write my own Dockerfile, based on the example of locale customization in Debian based image.
My Dockerfile:
In DB, I test the working of collation:
It returns the values in the wrong order: "BA", "Bi", "CA", "Ci", "DA", "Di", "be", "ce", "de", "ČA", "Či", "če"
I get the same result with:
SELECT * FROM test ORDER BY some_field COLLATE "C";
I do get the right result with an explicit:
SELECT * FROM test ORDER BY some_field COLLATE "sl-SI-x-icu";
The correct order is: "BA", "be", "Bi", "CA", "ce", "Ci", "ČA", "če", "Či", "DA", "de", "Di"
So Postgres CAN use the collation if instructed so explicitly in every statement (unpractical).
If I do
SHOW LC_COLLATE;
, it returns sl-SI-x-icu. So it should work, right?Well, if I change my dockerfile to intead say
ENV LANG ghjfgjfc
, the container sets up just fine and evenSHOW LC_COLLATE;
will return "ghjfgjfc" (a nonexistent locale), but keep on using C locale as default.If I were to set the same gibberish as the LANG environment variable in a Debian based image, it would error out and shut down.
Am I missing something trivial? Should I be setting environment variables differently? Can't it be done with said variables and it could be achieved with a custom initialiaztion script? Should I just give up on Alpine, use Debian and be done with it?
The text was updated successfully, but these errors were encountered: