Re: || versus concat( ), diff behavior

Поиск
Список
Период
Сортировка
От Philip Couling
Тема Re: || versus concat( ), diff behavior
Дата
Msg-id 4F513FBE.2040303@pedal.me.uk
обсуждение исходный текст
Ответ на || versus concat( ), diff behavior  (<david.sahagian@emc.com>)
Ответы Re: || versus concat( ), diff behavior  ("David Johnston" <polobo@yahoo.com>)
Список pgsql-general
On 02/03/12 20:58, david.sahagian@emc.com wrote:
> Can anybody please point me to where this "difference of behavior" is explained/documented ?
> Thanks,
> -dvs-
>
> -- version = 9.1.3
> do $$
> declare
>    v_str  char(10);
> begin
>    v_str := 'abc' ;
>    raise info '%', concat(v_str, v_str) ;
>    raise info '%', v_str||v_str ;
> end
> $$;
>
> INFO:  abc       abc
> INFO:  abcabc
>
>

Concat is a function which concatenates whatever you give it blindly.
Hence it has the behavior that includes the blanks.

The || operator reflects the more general PostgreSQL principle that
trailing blanks are insignificant for char fields.  You see the same
behavior when comparing char variables.


This can be found in the manual:

http://www.postgresql.org/docs/current/static/datatype-character.html

Values of type character are physically padded with spaces to the
specified width n, and are stored and displayed that way. However, the
padding spaces are treated as semantically insignificant. Trailing
spaces are disregarded when comparing two values of type character, and
they will be removed when converting a character value to one of the
other string types. Note that trailing spaces are semantically
significant in character varying and text values, and when using pattern
matching, e.g. LIKE, regular expressions.


Hope this makes it just a little clearer.

Regards

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

Предыдущее
От: Ben Chobot
Дата:
Сообщение: Re: || versus concat( ), diff behavior
Следующее
От: Piyush Lenka
Дата:
Сообщение: Restoring selected records from backup file