X-Original-To: pgsql-general@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B530E475E9D for ; Thu, 24 Apr 2003 05:15:14 -0400 (EDT) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by postgresql.org (Postfix) with ESMTP id 167F8474E42 for ; Thu, 24 Apr 2003 05:15:12 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) id 198coz-000NZW-0W; Thu, 24 Apr 2003 10:15:13 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id E8C65170AD; Thu, 24 Apr 2003 10:15:10 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 3CFDB170AA; Thu, 24 Apr 2003 10:15:09 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: milimeter@163.com, "milimeter@163.com" , pgsql-general@postgresql.org Subject: Re: jdbc problem Date: Thu, 24 Apr 2003 10:15:27 +0100 User-Agent: KMail/1.4.3 References: <200304240938.58666."milimeter@163.com"> In-Reply-To: <200304240938.58666."milimeter@163.com"> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200304241015.28464.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Spam-Status: No, hits=-32.4 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/1227 X-Sequence-Number: 41292 On Thursday 24 Apr 2003 2:38 am, milimeter@163.com wrote: > Hi, all > > I have a table: CREATE TABLE person (age char(4)) > After executing "select age from person" with jdbc, I extract the val= ue > with: > getInt("age") > Now is the problem, the same code can succeed on oracle, but on > postgresql, because of not triming space automaticlly, it cause an error. If you don't want space-padded text, don't use char(), use varchar(). The= =20 char(4) column *always* contains four characters (space padded). If for some reason you need to use char() types, then just trim it before= =20 applying getInt() or write your own function that can cope with trailing=20 spaces. > So, I hope the newest jdbc driver for postgresql can automaticlly trim > space just like oracle. The same problem also exists when execute insert: > Provided "age" is an integer, then "insert into person values ('30')" > can be executed correctly, but "insert into person values ('')" can not. = On > oracle, a default value will be added. So jdbc driver for postgresql shou= ld > also do it. Oracle is probably treating the empty string as a null, which is where your= =20 default value is coming from. It shouldn't do this, since the empty string = is=20 not null. Testing here, I can insert values of 30, '30', '' into a char(4) fine from = the=20 command-line. Ah! Unless where you say "age is an integer" you mean that th= e=20 age column is of type integer, in which case PG can't translate an empty=20 string into an integer (and nor can I). On the other hand, the string '30'= =20 can obviously be converted to an integer. --=20 Richard Huxton