Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VMQQD-0000mi-MR for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2013 22:40:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VMQQD-0004CE-5w for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2013 22:40:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VMQQB-0004AI-4l for pgsql-hackers@postgresql.org; Wed, 18 Sep 2013 22:40:31 +0000 Received: from mail-pb0-x22f.google.com ([2607:f8b0:400e:c01::22f]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VMQQ8-0004t1-S8 for pgsql-hackers@postgresql.org; Wed, 18 Sep 2013 22:40:30 +0000 Received: by mail-pb0-f47.google.com with SMTP id rr4so7570511pbb.6 for ; Wed, 18 Sep 2013 15:40:27 -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=DP4AIgNTgNs2g8CqVqU3C6iLGde3dTsj4GmvOYG2zmI=; b=GQSOh86TxF2tNSlZCZGtDhdnFu6Gocw6nv90+nGUoTjdq1FBJ6XcM4NeKOwbTSEgrf wNQQyPQSoi7fYKXLRQ1j+GMMZZFfRH6qC5gou8XZMlZusjXMMGSDuC9PH03Rzd9bu7f0 cybz4doB//O3glm3ibJRFuSz2PxnBXzttFAtPmzp/p4vU2zOjk7A0n+BNnRoqqyAOtQ+ JtiBmH+UzhTmlIA7D9v7CPHer16e/gSFovvuEsUAeOWVIYAkSMA9BhdCz3njRmoMlrLY T3BZypZ/SoPoD9xrtnfrTEG1OxXTD+t5qRwvN3YRwVCcFZJf2eJZtscpMxxuWxjQOOxI 9rww== X-Received: by 10.68.219.194 with SMTP id pq2mr27004665pbc.52.1379544027566; Wed, 18 Sep 2013 15:40:27 -0700 (PDT) Received: from maumau (p6019-ipbfp211sizuokaden.shizuoka.ocn.ne.jp. [114.170.213.19]) by mx.google.com with ESMTPSA id sb9sm5007345pbb.0.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 18 Sep 2013 15:40:26 -0700 (PDT) Message-ID: From: "MauMau" To: "Robert Haas" Cc: "Tom Lane" , "Boguk, Maksym" , "Heikki Linnakangas" , References: <522594E8.2050106@vmware.com><904.1378304922@sss.pgh.pa.us> In-Reply-To: Subject: Re: UTF8 national character data type support WIP patch and list of open issues. Date: Thu, 19 Sep 2013 07:42:29 +0900 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; 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.3 (-) 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 From: "Robert Haas" > On Mon, Sep 16, 2013 at 8:49 AM, MauMau wrote: >> 2. NCHAR/NVARCHAR columns can be used in non-UTF-8 databases and always >> contain Unicode data. > ... >> 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. > > It seems to me that these two points here are the real core of your > proposal. The rest is just syntactic sugar. No, those are "desirable if possible" features. What's important is to declare in the manual that PostgreSQL officially supports national character types, as I stated below. > 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. And when declaring that, we had better implement NCHAR types as distinct types with their own OIDs so that we can extend NCHAR behavior in the future. As the first stage, I think it's okay to treat NCHAR types exactly the same as CHAR/VARCHAR types. For example, in ECPG: switch (type) case OID_FOR_CHAR: case OID_FOR_VARCHAR: case OID_FOR_TEXT: case OID_FOR_NCHAR: /* new code */ case OID_FOR_NVARCHAR: /* new code */ some processing; break; And in JDBC, just call methods for non-national character types. Currently, those national character methods throw SQLException. public void setNString(int parameterIndex, String value) throws SQLException { setString(parameterIndex, value); } > Let me start with the second one: I don't think there's likely to be > any benefit in using UTF-16 as the internal encoding. In fact, I > think it's likely to make things quite a bit more complicated, because > we have a lot of code that assumes that server encodings have certain > properties that UTF-16 doesn't - specifically, that any byte with the > high-bit clear represents the corresponding ASCII character. > > As to the first one, if we're going to go to the (substantial) trouble > of building infrastructure to allow a database to store data in > multiple encodings, why limit it to storing UTF-8 in non-UTF-8 > databases? What about storing SHIFT-JIS in UTF-8 databases, or > Windows-yourfavoriteM$codepagehere in UTF-8 databases, or any other > combination you might care to name? > > Whether we go that way or not, I think storing data in one encoding in > a database with a different encoding is going to be pretty tricky and > require far-reaching changes. You haven't mentioned any of those > issues or discussed how you would solve them. Yes, you are probably right -- I'm not sure UTF-16 has really benefits that UTF-8 doesn't have. But why did Windows and Java choose UTF-16 for internal strings rather than UTF-8? Why did Oracle recommend UTF-16 for NCHAR? I have no clear idea. Anyway, I don't strongly push UTF-16 and complicate the encoding handling. 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