2017-05-10 12 views
1

를 사용하는 사이에 다른 : 모두에열이 나는이 같은 모두 내 Mac 및 우분투 서버에서 UTF8 인코딩 및 fr_FR의 데이터 정렬과 데이터베이스를 만든 맥 OS와 우분투 같은 정렬

CREATE DATABASE my_database OWNER 'admin' TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'fr_FR.UTF-8' LC_CTYPE 'fr_FR.UTF-8'; 

, 나는 정렬을 조회 :

show lc_collate; 

및 얻을 :

fr_FR.UTF-8 

을 그럼,의에 시도 오트 동일한 데이터베이스 및 취득하지 않았다 같은 결과 :

SELECT winery FROM usr_wines WHERE user_id=1 AND status=1 ORDER BY winery LIMIT 5; 

1 - 맥 OS의 경우 : 우분투 14.04에

a space before the a 
A New record 
Aa 
Altesinoo 
Aé 

2 : 우분투에

Aa 
Aé 
Altesino 
A New Wine 
a space before a 

, 내가 설치 한 원하는 로케일을 선택하고 새로운 데이터 정렬을 만듭니다.

CREATE COLLATION "fr_FR.utf8" (LOCALE = "fr_FR.utf8") 

select * from pg_collation; 

    collname | collnamespace | collowner | collencoding | collcollate | collctype 
------------+---------------+-----------+--------------+-------------+------------ 
default |   11 |  10 |   -1 |    | 
C   |   11 |  10 |   -1 | C   | C 
POSIX  |   11 |  10 |   -1 | POSIX  | POSIX 
C.UTF-8 |   11 |  10 |   6 | C.UTF-8  | C.UTF-8 
en_US  |   11 |  10 |   6 | en_US.utf8 | en_US.utf8 
en_US.utf8 |   11 |  10 |   6 | en_US.utf8 | en_US.utf8 
ucs_basic |   11 |  10 |   6 | C   | C 
fr_FR  |   2200 |  10 |   6 | fr_FR.utf8 | fr_FR.utf8 

mac에서 fr_FR 데이터 정렬이 이미 설치되었습니다.

왜 이러한 정렬 차이가 있습니까?

우분투 또 다른 이상한 문제 : 내 요청에 정렬을 강제로 시도 FI는 :

SELECT winery FROM usr_wines WHERE user_id=1 AND status=1 ORDER BY winery COLLATE "fr_FR" LIMIT 5; 

내가 가지고 :

ERROR: collation "fr_FR" for encoding "UTF8" does not exist

어떤 도움을 환영합니다.

+1

이 알려진 문제 - 전용 데이터 정렬'은 포스트 그레스에 의존로 C'는 OS –

+0

에 당신이 사용하는 모든 플랫폼에서 동일한 정렬을 볼 수있는 방법은 없습니다 의미하지, 같은 결과를 줄 것이다 동일한 데이터 정렬, C 데이터 정렬 제외. 이것은 이상하게 보입니다. 예를 들어, MySQL 유니 코드 데이터 정렬을 사용하여이 동작을 수행하지 못했습니다. –

+0

아마도 mysql은 os 데이터 정렬을 사용하지 않을 것입니다. –

답변

1

"C"는 모든 플랫폼에서 예측 가능한 결과를 제공합니다.Additional collations may be available depending on operating system support. 따라서 OS의 동작은 전적으로 OS에 따라 다릅니다.

https://www.postgresql.org/docs/current/static/collation.html :

On all platforms, the collations named default, C, and POSIX are available. Additional collations may be available depending on operating system support. The default collation selects the LC_COLLATE and LC_CTYPE values specified at database creation time. The C and POSIX collations both specify "traditional C" behavior, in which only the ASCII letters "A" through "Z" are treated as letters, and sorting is done strictly by character code byte values.

If the operating system provides support for using multiple locales within a single program (newlocale and related functions), then when a database cluster is initialized, initdb populates the system catalog pg_collation with collations based on all the locales it finds on the operating system at the time. For example, the operating system might provide a locale named de_DE.utf8. initdb would then create a collation named de_DE.utf8 for encoding UTF8 that has both LC_COLLATE and LC_CTYPE set to de_DE.utf8. It will also create a collation with the .utf8 tag stripped off the name. So you could also use the collation under the name de_DE, which is less cumbersome to write and makes the name less encoding-dependent. Note that, nevertheless, the initial set of collation names is platform-dependent.