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

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: String concatenation operator which keeps trailing spaces in CHAR(n) columns
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B17D214C0@ntex2010i.host.magwien.gv.at
обсуждение исходный текст
Ответ на String concatenation operator which keeps trailing spaces in CHAR(n) columns  ("Andrus" <kobruleht2@hot.ee>)
Ответы Re: String concatenation operator which keeps trailing spaces in CHAR(n) columns  ("Andrus" <kobruleht2@hot.ee>)
Список pgsql-general
Andrus wrote:
> 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

Use "bpchar" instead of "text" in the definition of function and operator.

Otherwise col1 gets cast to "text" and loses its trailing spaces.

Yours,
Laurenz Albe

В списке pgsql-general по дате отправления:

Предыдущее
От: "Andrus"
Дата:
Сообщение: String concatenation operator which keeps trailing spaces in CHAR(n) columns
Следующее
От: "Andrus"
Дата:
Сообщение: Re: String concatenation operator which keeps trailing spaces in CHAR(n) columns