pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Gibson (DB Administrator) <postgresql@ultimeth.com>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Trailing spaces - is there an easier way?
Date: Thu, 04 Nov 2010 12:03:48 -0700
Message-ID: <4CD30394.1030106@ultimeth.com> (raw)

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?

view thread (3+ messages)  latest in thread

Message-ID: <4CD30394.1030106@ultimeth.com>
Permalink:  ../4CD30394.1030106@ultimeth.com/
Also on:    postgresql.org/message-id/4CD30394.1030106@ultimeth.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: postgresql@ultimeth.com
  Subject: Re: Trailing spaces - is there an easier way?
  In-Reply-To: <4CD30394.1030106@ultimeth.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox