Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLYE1-0002fc-KU for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Sep 2013 12:48:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VLYE1-0006Gd-0L for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Sep 2013 12:48:21 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLYDz-0006GT-M7 for pgsql-hackers@postgresql.org; Mon, 16 Sep 2013 12:48:19 +0000 Received: from mail-pd0-x234.google.com ([2607:f8b0:400e:c02::234]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLYDw-0006OX-BU for pgsql-hackers@postgresql.org; Mon, 16 Sep 2013 12:48:18 +0000 Received: by mail-pd0-f180.google.com with SMTP id y10so4042857pdj.39 for ; Mon, 16 Sep 2013 05:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:references:in-reply-to:subject:date :mime-version:content-type:content-transfer-encoding; bh=YaHLjdkYdO1EFWWqaBmivkqxdhQia3y2A+E32SH4sCk=; b=VIcGk77UT3j/BwjA90qb/iotSt5k9FMJRnbH7E99Ch0sEbb27N+9s824zvfRDAkqqF +Y+nArysKI+TA/+zUE3xWo1NrwFjeam6spXGA+Nx8SeIerTKTcgvOKSJdxMhLKt3w3md a1DpBv9PKqfKDYvhIEhZsHXGtGhTywJuFu9AGtxSKj+xWyoIn1s0iG0x/Loxg8c+GXma OG89WwDTgIVUMYSfhbdwAkYPpktYfpYhB+L06SNe5DqvqolEGRzQmh3RDKvll1E4RANo 87tLZSwnn8CDFeVsiS6xADNOt2u5CxWcElKW1cU4OT3Fmk38IPAubtr5KpjeyQQNZ3xa 5IrQ== X-Received: by 10.66.171.77 with SMTP id as13mr1716457pac.170.1379335694993; Mon, 16 Sep 2013 05:48:14 -0700 (PDT) Received: from maumau (p6019-ipbfp211sizuokaden.shizuoka.ocn.ne.jp. [114.170.213.19]) by mx.google.com with ESMTPSA id xs1sm38481470pac.7.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Sep 2013 05:48:13 -0700 (PDT) Message-ID: From: "MauMau" To: "Tom Lane" , "Boguk, Maksym" Cc: "Heikki Linnakangas" , References: <522594E8.2050106@vmware.com> <904.1378304922@sss.pgh.pa.us> In-Reply-To: <904.1378304922@sss.pgh.pa.us> Subject: Re: UTF8 national character data type support WIP patch and list of open issues. Date: Mon, 16 Sep 2013 21:49:52 +0900 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-2022-jp"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6002.18197 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6002.18463 X-Pg-Spam-Score: 1.4 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hello, I think it would be nice for PostgreSQL to support national character types largely because it should ease migration from other DBMSs. [Reasons why we need NCHAR] -------------------------------------------------- 1. Invite users of other DBMSs to PostgreSQL. Oracle, SQL Server, MySQL, etc. all have NCHAR support. PostgreSQL is probably the only database out of major ones that does not support NCHAR. Sadly, I've read a report from some Japanese government agency that the number of MySQL users exceeded that of PostgreSQL here in Japan in 2010 or 2011. I wouldn't say that is due to NCHAR support, but it might be one reason. I want PostgreSQL to be more popular and regain those users. 2. Enhance the "open" image of PostgreSQL by implementing more features of SQL standard. NCHAR may be a wrong and unnecessary feature of SQL standard now that we have Unicode support, but it is defined in the standard and widely implemented. 3. I have heard that some potential customers didn't adopt PostgreSQL due to lack of NCHAR support. However, I don't know the exact reason why they need NCHAR. 4. I guess some users really want to continue to use ShiftJIS or EUC_JP for database encoding, and use NCHAR for a limited set of columns to store international text in Unicode: - to avoid code conversion between the server and the client for performance - because ShiftJIS and EUC_JP require less amount of storage (2 bytes for most Kanji) than UTF-8 (3 bytes) This use case is described in chapter 6 of "Oracle Database Globalization Support Guide". -------------------------------------------------- I think we need to do the following: [Minimum requirements] -------------------------------------------------- 1. Accept NCHAR/NVARCHAR as data type name and N'...' syntactically. This is already implemented. PostgreSQL treats NCHAR/NVARCHAR as synonyms for CHAR/VARCHAR, and ignores N prefix. But this is not documented. 2. Declare support for national character support in the manual. 1 is not sufficient because users don't want to depend on undocumented behavior. This is exactly what the TODO item "national character support" in PostgreSQL TODO wiki is about. 3. Implement NCHAR/NVARCHAR as distinct data types, not as synonyms so that: - psql \d can display the user-specified data types. - pg_dump/pg_dumpall can output NCHAR/NVARCHAR columns as-is, not as CHAR/VARCHAR. - To implement additional features for NCHAR/NVARCHAR in the future, as described below. -------------------------------------------------- [Optional requirements] -------------------------------------------------- 1. Implement client driver support, such as: - NCHAR host variable type (e.g. "NCHAR var_name[12];") in ECPG, as specified in the SQL standard. - national character methods (e.g. setNString, getNString, setNCharacterStream) as specified in JDBC 4.0. I think at first we can treat these national-character-specific features as the same as CHAR/VARCHAR. 2. NCHAR/NVARCHAR columns can be used in non-UTF-8 databases and always contain Unicode data. I think it is sufficient at first that NCHAR/NVARCHAR columns can only be used in UTF-8 databases and they store UTF-8 strings. This allows us to reuse the input/output/send/recv functions and other infrastructure of CHAR/VARCHAR. This is a reasonable compromise to avoid duplication and minimize the first implementation of NCHAR support. 3. Store strings in UTF-16 encoding in NCHAR/NVARCHAR columns. Fixed-width encoding may allow faster string manipulation as described in Oracle's manual. But I'm not sure about this, because UTF-16 is not a real fixed-width encoding due to supplementary characters. -------------------------------------------------- I don't think it is good to implement NCHAR/NVARCHAR types as extensions like contrib/citext, because NCHAR/NVARCHAR are basic types and need client-side support. That is, client drivers need to be aware of the fixed NCHAR/NVARCHAR OID values. How do you think we should implement NCHAR support? Regards MauMau -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers