X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 51211DA9F2 for ; Fri, 21 Oct 2005 20:28:51 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22978-08 for ; Fri, 21 Oct 2005 23:28:45 +0000 (GMT) Received: from mail.mailpen.net (mail.mailpen.net [66.235.70.248]) by svr1.postgresql.org (Postfix) with ESMTP id 8FD29DA988 for ; Fri, 21 Oct 2005 20:28:47 -0300 (ADT) Received: from athlon1.internal.mailpen.net (pool-71-113-21-206.sttlwa.dsl-w.verizon.net [71.113.21.206]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.mailpen.net (Postfix) with ESMTP id F251316 for ; Fri, 21 Oct 2005 16:28:49 -0700 (PDT) Received: from [192.168.128.199] (TpA22p1.internal.mailpen.net [192.168.128.199]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by athlon1.internal.mailpen.net (Postfix) with ESMTP id AA77C6DC060 for ; Fri, 21 Oct 2005 16:28:48 -0700 (PDT) Message-ID: <435979B0.60107@ultimeth.com> Date: Fri, 21 Oct 2005 16:28:48 -0700 From: "Dean Gibson (DB Administrator)" Organization: UltiMeth Systems User-Agent: Thunderbird 1.4.1 (Windows/20051006) MIME-Version: 1.0 To: pgsql-sql Subject: Blank-padding (was: Oracle buys Innobase) References: <878xwokk4d.fsf@charter.net> <20051020214518.Q1006@ganymede.hub.org> <33c6269f0510210716x474dae2ah3861d32d8db01602@mail.gmail.com> <23805.1129913241@sss.pgh.pa.us> In-Reply-To: <23805.1129913241@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/251 X-Sequence-Number: 23104 On 2005-10-21 09:47, Tom Lane wrote: > Alex Turner writes: > >> It appears that casting to a char() causes spaces to be stripped (ignored) from the string: >> > mls=# select length('123 '::char(8)); > length > -------- > 3 > (1 row) > > >> I'm not sure about anyone else, but I would personaly consider that a bug? >> > > No, it's a feature, as per extensive discussion some time ago when we made it do that. The general rule is that trailing spaces in a char(n) are semantically insignificant. > > regards, tom lane > I remember that discussion, and I was for the change. However, upon doing some testing after reading the above, I wonder if the blank-stripping isn't too aggressive. I have a CHAR(6) field (say, named Z) that has "abc " in it. Suppose I want to append "x" to Z, with any leading spaces in Z PRESERVED. The following do not work in 8.0.4: select Z || 'x'; select Z::char(6) || 'x'; select Z::varchar(6) || 'x'; select (Z || ' ')::char(6) || 'x'; There are only two ways I've found: select rpad( Z, 6) || 'x'; -- but "rpad" is apparently not a SQL-standard function. select cast (Z || ' ' as varchar(6)) || 'x'; -- hokey but SQL-compliant Is there something I'm missing??? -- Dean