Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 24B4D634CD7 for ; Sat, 29 May 2010 07:04:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 90799-10 for ; Sat, 29 May 2010 10:04:09 +0000 (UTC) X-Greylist: delayed 00:52:18.626398 by SQLgrey-1.7.6 Received: from faith.micfo.com (faith.micfo.com [64.120.14.82]) by mail.postgresql.org (Postfix) with ESMTP id D998C634CE5 for ; Sat, 29 May 2010 07:04:10 -0300 (ADT) Received: from 87-204-194-135.dg-net.pl ([87.204.194.135]:55000 helo=radek.localnet) by faith.micfo.com with esmtpa (Exim 4.69) (envelope-from ) id 1OII55-00038f-UE for pgsql-jdbc@postgresql.org; Sat, 29 May 2010 04:11:48 -0500 From: =?utf-8?q?Rados=C5=82aw_Smogura?= To: pgsql-jdbc@postgresql.org Subject: Re: Using java.lang.Character for "char" data type Date: Sat, 29 May 2010 11:12:56 +0200 User-Agent: KMail/1.12.4 (Linux/2.6.31-gentoo-r10; KDE/4.3.5; x86_64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201005291112.56261.mail@smogura.eu> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - faith.micfo.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - smogura.eu X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201005/86 X-Sequence-Number: 20570 Dnia sobota 22 maj 2010 o 03:11:52 Lew napisa=C5=82(a): > I'm a little confused. When you say "char" is a byte long, are you > referring to the SQL type or the Java type? I'm used to seeing the Java > type expressed in lower case and the SQL type in upper case, so please > pardon my confusion. >=20 > The Java 'char' type is 16 bits wide. >=20 > Doesn't the width of the SQL "CHAR" depend on the encoding? >=20 > Otherwise how does it handle, say, UTF-8 when you tell the DB to use that? >=20 > To put it another way, suppose I enter a String that contains, say, 24 > UTF-8 characters, some of which require multibyte encodings, and try to > jam it into a "CHAR(24)" column or a "VARCHAR(24)" column. Will that > cause trouble? >=20 > The documentation for CHAR and VARCHAR at > > says > "SQL defines two primary character types: character varying(n) and > character(n), where n is a positive integer. Both of these types can store > strings up to n characters (not bytes) in length." >=20 > That seems to contradict what you said. >=20 As it was said Java char is 16 bits length and it can represent all Java=20 available caharacters (internally it's UTF-16 with small modification). Whe= n=20 you say about SQL CHAR it represents one character from all possible SQL=20 characters - nothing special, it's truism :) This possible SQL characters, are described by DB encoding if you will uses= 8=20 bit encoding (ASCII, ISO, etc) then you can put about 256 types of characte= rs=20 in one slot (eg. in DB with ASCII encoding you can't put ISO-8859-2 letters= ,DB=20 encoding is used only to describe this possible characters and how those ar= e=20 stored on disk in binary form (it's same as system encoding when you use te= xt=20 based file read and write, or what internal encoding file system entry will= =20 have). Ofcourse CHAR(1) should store any character from set of possible DB's=20 characters (determined by encoding). Difference between CHAR and VARCHAR is store strategy VARCHAR string is=20 variable length, but CHAR(n) string always has length n. If you will put to= =20 CHAR(2) only "A" the select will return "A " (space at the end). So answer for your question is "You should not care about bit length until= =20 your DB encdoing will support all your characters or until your task is to= =20 optimize or predicate the size of DB files". You should leave bit length of= SQL=20 characters to DB engine. I use UTF-8 database and I see no problem with thi= s.=20 If you don't belive you can check this.