| From: | "Dean Gibson (DB Administrator)" <postgresql(at)ultimeth(dot)com> |
|---|---|
| To: | pgsql-sql <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Trailing spaces - is there an easier way? |
| Date: | 2010-11-04 19:03:48 |
| Message-ID: | 4CD30394.1030106@ultimeth.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
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?
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pavel Stehule | 2010-11-04 19:42:21 | Re: Trailing spaces - is there an easier way? |
| Previous Message | Tom Lane | 2010-11-04 03:50:08 | Re: I'm stuck - I just can't get this small FUNCT to run! |