Subject RE: [firebird-support] Changing field size to smaller
Author Helen Borrie
At 02:59 PM 10/08/2004 +0300, you wrote:
>I use this script (DETAILS was varchar(210)):
>
>ALTER TABLE corresp add TEMP Varchar(140) CHARACTER SET WIN1252 COLLATE
>WIN1252;
>update corresp set temp=details;
>ALTER TABLE corresp drop details;
>ALTER TABLE corresp add details Varchar(140) CHARACTER SET WIN1252
>COLLATE WIN1252;
>update corresp set details=TEMP;
>ALTER TABLE corresp drop TEMP;
>
>I can't move the data! Script causes "arithmetic or string truncation
>error" when old Details field data is longer than 140

Yes, of course it does.
You need to perform an update on TEMP first, to reduce the size of the
data, before trying to move the data into the new details column:

update corresp
set TEMP = substring(TEMP from 1 for 140);

Note, the substring() function works only in Firebird. If you're still
using IB, you'll need to use the substr() UDF. It has a different (and
curious) syntax and will throw an exception on any data that is shorter
than 140. Needs to be managed via a stored procedure so you can test the
length of the data using the strlen() UDF. Take care to declare substr()
with parameters of sufficient length.

/heLen