String concatenation operator which keeps trailing spaces in CHAR(n) columns

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: <pgsql-general(at)postgresql(dot)org>
Subject: String concatenation operator which keeps trailing spaces in CHAR(n) columns
Date: 2014-07-30 10:43:39
Message-ID: 85033C87F2984B1B878D9718B790702D@dell2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How to create string concatenation operator which preserves trailing spaces
on CHAR(n) type columns ?

I tried code below, but it returns AB (without spaces).
How to force it to return A B (keep space after A) ?

Andrus.

CREATE OR REPLACE FUNCTION public.stringconcat(left text, right text)
RETURNS text
LANGUAGE sql IMMUTABLE
AS $BODY$
SELECT concat($1, $2) ;
$BODY$;

CREATE OPERATOR public.+ (
leftarg = text,
rightarg = text,
procedure = public.stringconcat
);

create temp table test (col1 char(2)) on commit drop;
insert into test values ('A');
select col1 + 'B'
from test;

I posted similar question also in

http://stackoverflow.com/questions/24975118/how-to-create-string-concatenation-operator-which-preserves-trailing-spaces-in-c

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2014-07-30 11:07:08 Re: String concatenation operator which keeps trailing spaces in CHAR(n) columns
Previous Message Sergey Konoplev 2014-07-30 05:27:25 Re: statement_timeout doesn't work