Re: || versus concat( ), diff behavior

From: Ben Chobot <bench(at)silentmedia(dot)com>
To: <david(dot)sahagian(at)emc(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: || versus concat( ), diff behavior
Date: 2012-03-02 21:14:50
Message-ID: A042A0C8-7BE2-4E0D-B71F-F221626D6614@silentmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mar 2, 2012, at 12:58 PM, <david(dot)sahagian(at)emc(dot)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

I'm not sure why || works differently than concat(), but char() is whitespace-padded. You told the db you wanted "10 characters", so that's what it gave you. Perhaps you wanted vchar(10)? For that matter, do you even want that restriction of 10 characters in the first place? Perhaps the type text is what you're really after?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Philip Couling 2012-03-02 21:46:38 Re: || versus concat( ), diff behavior
Previous Message david.sahagian 2012-03-02 20:58:22 || versus concat( ), diff behavior