Thread: is it a bug?

is it a bug?

From
"He weiping"
Date:
I'm using cvs-current, and testing those build-in function
according to the docs.
but it seems the "lpad", "rpad" don't work,
when I type:
select lpad('laser', 4, 'a');
in psql, the result is still
'laser', the same with 'rpad',
Is it a bug or I'm mis-understaning the lpad and/or rpad functions?
 
Regards
 
Laser

Re: is it a bug?

From
Thomas Lockhart
Date:
> ... it seems the "lpad", "rpad" don't work,
> when I type:
> select lpad('laser', 4, 'a');
> in psql, the result is still
> 'laser', the same with 'rpad',
> Is it a bug or I'm mis-understaning the lpad and/or rpad functions?

A simple misunderstanding. The length argument is for the *total*
length. So padding a 5 character string to a length of 4 will do
nothing. But padding to a length of 6 will add a single "a" to the
string.

                        - Thomas

Re: [GENERAL] is it a bug?

From
Tom Lane
Date:
"He weiping" <laser@zhengmai.com.cn> writes:
> but it seems the "lpad", "rpad" don't work,
> when I type:
> select lpad('laser', 4, 'a');
> in psql, the result is still=20
> 'laser', the same with 'rpad',
> Is it a bug or I'm mis-understaning the lpad and/or rpad functions?

lpad and rpad never truncate, they only pad.

Perhaps they *should* truncate if the specified length is less than
the original string length.  Does Oracle do that?

            regards, tom lane