Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 2DD151337B82 for ; Thu, 4 Nov 2010 16:47:55 -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 32790-05 for ; Thu, 4 Nov 2010 19:47:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh3.mail.rice.edu (mh3.mail.rice.edu [128.42.199.10]) by mail.postgresql.org (Postfix) with ESMTP id 0A8491337B8D for ; Thu, 4 Nov 2010 16:47:47 -0300 (ADT) Received: from mh3.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh3.mail.rice.edu (Postfix) with ESMTP id CC60428F6E3; Thu, 4 Nov 2010 14:47:46 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.4 at mh3.mail.rice.edu, auth channel Received: from mh3.mail.rice.edu ([127.0.0.1]) by mh3.mail.rice.edu (mh3.mail.rice.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id urtqsKkfrtUA; Thu, 4 Nov 2010 14:47:46 -0500 (CDT) X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh3.mail.rice.edu (Postfix) with ESMTP id A0BD528F6E0; Thu, 4 Nov 2010 14:47:46 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id 6EAF32D5A6; Thu, 4 Nov 2010 14:47:46 -0500 (CDT) Date: Thu, 4 Nov 2010 14:47:46 -0500 From: Kenneth Marshall To: Pavel Stehule Cc: "Dean Gibson (DB Administrator)" , pgsql-sql Subject: Re: Trailing spaces - is there an easier way? Message-ID: <20101104194746.GK27429@aart.is.rice.edu> References: <4CD30394.1030106@ultimeth.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/10 X-Sequence-Number: 34748 On Thu, Nov 04, 2010 at 08:42:21PM +0100, Pavel Stehule wrote: > 2010/11/4 Dean Gibson (DB Administrator) : > > I'm sure this has been asked before, but I couldn't find it: > > > > I have a "zzz CHAR (8)" field.?? It needs to be CHAR because trailing spaces > > need to be ignored for most operations.?? However, I need to concatenate it > > with another (literal) string and need the spaces to be significant in that > > operation.?? The ONLY WAY I could find to do it?? in v9.0.1 was (represented > > in the following function): > > > > CREATE OR REPLACE FUNCTION padded( field CHAR ) RETURNS TEXT > > ?????? RETURNS NULL ON NULL INPUT > > ?????? IMMUTABLE > > ?????? LANGUAGE SQL AS $SQL$ > > ?????????????? SELECT RPAD( $1, OCTET_LENGTH( $1 ) ) > > ?????? $SQL$; > > > > And then of course I write: > > > > SELECT padded( zzz ) || '/' || ... > > > > Is there a better way? > > > > > > nic=# SELECT 'AAAA '::char(6) || 'bbbb'; > ?column? > ---------- > AAAAbbbb > (1 row) > > Time: 2.710 ms > nic=# SELECT 'AAAA '::char(6)::cstring || 'bbbb'; > ?column? > ------------ > AAAA bbbb > (1 row) > > > regards > > Pavel Stehule > Here is a link to some useful other pseudo types: http://www.postgresql.org/docs/9.0/interactive/datatype-pseudo.html Regards, Ken