Re: [GENERAL] Not able to create collation on Windows

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Murtuza Zabuawala <murtuza(dot)zabuawala(at)enterprisedb(dot)com>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: [GENERAL] Not able to create collation on Windows
Date: 2017-08-01 14:53:15
Message-ID: 14439.1501599195@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Murtuza Zabuawala <murtuza(dot)zabuawala(at)enterprisedb(dot)com> writes:
> I am trying to create collation on windows using default POSIX collation
> with pgAdmin3 but I am getting error as shown in screenshot, Can someone
> suggest how to fix this?

> *Syntax:*
> CREATE COLLATION public.test from pg_catalog."POSIX";

> *Error:*
> ERROR: could not create locale "POSIX". No error

Hmm. Evidently Windows' _create_locale() doesn't accept "POSIX".
You might find that "C" works instead, don't know for sure.

I think this is actually a bug, because the collations code clearly
means to allow clones of the C/POSIX locales --- see eg lc_collate_is_c,
which could be noticeably simpler if that case weren't contemplated.
However, DefineCollation checks validity of the new collation by
unconditionally calling pg_newlocale_from_collation(). That violates
the advice in pg_newlocale_from_collation's header comment:

* Also, callers should avoid calling this before going down a C/POSIX
* fastpath, because such a fastpath should work even on platforms without
* locale_t support in the C library.

Every other call site honors that.

So I think what we ought to do is change DefineCollation more or
less like this:

- (void) pg_newlocale_from_collation(newoid);
+ if (!lc_collate_is_c(newoid) || !lc_ctype_is_c(newoid))
+ (void) pg_newlocale_from_collation(newoid);

Another issue exposed by this report is that we aren't reporting
_create_locale() failures in a useful way. It's possible this
could be improved by inserting

#ifdef WIN32
_dosmaperr(GetLastError());
#endif

into report_newlocale_failure in pg_locale.c, but I'm not really
sure. Microsoft's man page for _create_locale() fails to say much
of anything about its error-case behavior, and definitely does not
say that it sets the GetLastError indicator. Still, there's certainly
no chance that printing errno without doing this will be useful.
I would suggest that we do that for starters, and if we hear that
we're still getting silly errors, just hot-wire the code to assume
ENOENT on Windows.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2017-08-01 15:35:38 Re: [GENERAL] Not able to create collation on Windows
Previous Message Thomas Güttler 2017-08-01 14:11:35 Logging in Code vs SQL-WHERE was: Row based permissions: at DB or at Application level?

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2017-08-01 15:28:26 Re: PostgreSQL 10 (latest beta) and older ICU
Previous Message Michael Paquier 2017-08-01 14:35:55 Re: How to run PG TAP tests on windows?