Subject | Re: [firebird-support] Result type of RPAD() and LPAD() |
---|---|
Author | Kjell Rilbe |
Post date | 2011-01-10T11:23:32Z |
Kjell Rilbe skriver:
select rpad("x", 6, '-') from thetable
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64
> Paul Vinkenoog skriver:Sorry, that should be:
>> > In the documentation for LPAD and RPAD is written that the result
>> type is VARCHAR(32765) and there is a tip to cast the result to a useful
>> length.
>> >
>> > When using LPAD or RPAD in a "SELECT LPAD( LABEL, 8, '-' ) FROM...",
>> FlameRobin and IBExpert both return a VARCHAR(8), corresponding to the
>> length argument of xPAD(), without casting.
>>
>> In Firebird 2.5, the result is VARCHAR(n) with n equal to the second
>> argument.
>
> Does this mean that if I have a varchar(n) col and want to pad those
> values that are shorter than k chars to m chars (n>= m>= k), I can't
> do it without also truncating values longer than m to m chars?
>
> E.g. column "x" is varchar(10) and I have these values:
>
> 'abcdefghij'
> 'a'
> 'abcde'
>
> select rpad("x", '-', 6) from thetable
select rpad("x", 6, '-') from thetable
> would return this:--
>
> 'abcdef'
> 'a-----'
> 'abcde-'
>
> Or would it throw an exception?
>
> Kjell
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64