Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 728D6632B96 for ; Fri, 3 Apr 2009 10:29:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 21489-09 for ; Fri, 3 Apr 2009 10:28:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from QMTA14.emeryville.ca.mail.comcast.net (qmta14.emeryville.ca.mail.comcast.net [76.96.27.212]) by mail.postgresql.org (Postfix) with ESMTP id 9694C63281F for ; Fri, 3 Apr 2009 10:28:57 -0300 (ADT) Received: from OMTA07.emeryville.ca.mail.comcast.net ([76.96.30.59]) by QMTA14.emeryville.ca.mail.comcast.net with comcast id b0ar1b0051GXsucAE1Uxf8; Fri, 03 Apr 2009 13:28:57 +0000 Received: from tucker.local ([24.17.164.54]) by OMTA07.emeryville.ca.mail.comcast.net with comcast id b1Uv1b00K1Ak4z48T1UwcK; Fri, 03 Apr 2009 13:28:57 +0000 From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: Text cast problem Date: Fri, 3 Apr 2009 06:28:54 -0700 User-Agent: KMail/1.9.10 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200904030628.54639.aklaver@comcast.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.179 tagged_above=0 required=5 tests=AWL=0.179 X-Spam-Level: X-Archive-Number: 200904/30 X-Sequence-Number: 32376 On Thursday 02 April 2009 2:51:30 am Volkmar Herbst wrote: > Dear all- > > I encountered the following problem: > > > > select * from parcel where number =3D '255 ' > > gives me 1 row but > > > > select * from parcel where number =3D '255 ' ::text > > does give me 0 rows. The cast removes the trailing empty character. > > > > Why is that? Unfortunately the statements are generated (NPGSQL) and I > can=E2=80=99t change the way they are generated. What can I do? Any sugge= stions > highly welcomed! The why is here: http://www.postgresql.org/docs/8.3/interactive/datatype-character.html In particular: "Values of type character are physically padded with spaces to the specifie= d=20 width n, and are stored and displayed that way. However, the padding spaces= are=20 treated as semantically insignificant. Trailing spaces are disregarded when= =20 comparing two values of type character, and they will be removed when=20 converting a character value to one of the other string types. Note that=20 trailing spaces are semantically significant in character varying and text= =20 values. " What I have done in a similar situation is put a trigger on the table that = trims=20 the strings on INSERT or UPDATE.=20 > > > > Volkmar =2D-=20 Adrian Klaver aklaver@comcast.net