Subject Re: [firebird-support] altering a domain
Author Helen Borrie
At 06:44 PM 21/03/2005 +0000, you wrote:


>I have a column associated with a domain defined as 'VARCHAR(200)
>CHARACTER SET NONE' and want to assign it to a domain defined as 'BLOB
>SUB_TYPE 1 SEGMENT SIZE 100'. Is that allowed, ie will my current data
>persist? (Is there any way of knowing what is/isn't allowed?).

Data type conversions are not possible through DDL changes, i.e. by ALTER
DOMAIN or ALTER TABLE ALTER COLUMN TYPE.... So, for example, it's possible
to increase the size of a varchar domain or to convert smallint to integer
or integer to BigInt, etc., but not to convert data from one type to an
entirely different type.

Blob and text are not compatible data types. However, the Firebird engine
knows how to convert strings to blobs transparently to text blobs in DML
statements. You can use this to assist you in a string-to-textblob
conversion (though it doesn't work the other way around).

There will be various ways to go about changing the data type of the field,
all involving pumping your text data to a temporary column. I suggest the
following (committing after each step):

1. create a new domain of BLOB SUB_TYPE 1.
2. create a new column in the table of the old domain.
3. use an update statement to pump all of the varchar data to the temp
column.
4. drop the original column
5. recreate the old column using the new domain
6. update the recreated column:

update TheTable
set TheColumn = TempColumn;
7. Drop the temp column
8. you can now drop the old domain, if it's not being used for any other
columns.

./heLen