Subject Re: [firebird-support] Result type of RPAD() and LPAD()
Author Kjell Rilbe
Kjell Rilbe skriver:
> Kjell Rilbe skriver:
>> Paul Vinkenoog skriver:
>>> > 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
>
> Sorry, that should be:
> select rpad("x", 6, '-') from thetable
>
>> would return this:
>>
>> 'abcdef'
>> 'a-----'
>> 'abcde-'

I tried it in 2.1.3.18185. It truncates to 6 chars.

So, padding to less than the longest occurring value would require
something like this, then:

select
case
when character_length(x) > 6
then x
else rpad(x, 6, '-')
end "Result"
from thetable

But when I tried this, I got an error:
------------------------------------
Message: isc_dsql_prepare failed

SQL Message : -204
Undefined name

Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -204
Implementation limit exceeded
block size exceeds implementation restriction
------------------------------------

What limit did I exceed exactly?

Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64