On 14-08-2020 04:55, Lucas Schatz wrote:
> I think something like:
> ALTER TABLE TEST_TABLE ALTER COLUMN NUMERIC_FIELD TYPE integer
> CONVERTING WITH round(value);
> ALTER TABLE TEST_TABLE ALTER COLUMN STRING_FIELD TYPE varchar(5)
> CONVERTING WITH substring(value from 1 for 5);
>
> I don't know if there is another easier way to do it, if exists, please
> let me know!
> Thanks for any help, advise or implementation! :D
Unfortunately Firebird doesn't have such a feature. I'd recommend
creating a ticket in the tracker for this.
PostgreSQL offers something like this with its USING clause:
ALTER TABLE name
ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type [ COLLATE
collation ] [ USING expression ]
"""
SET DATA TYPE
This form changes the type of a column of a table. Indexes and
simple table constraints involving the column will be automatically
converted to use the new column type by reparsing the originally
supplied expression. The optional COLLATE clause specifies a collation
for the new column; if omitted, the collation is the default for the new
column type. The optional USING clause specifies how to compute the new
column value from the old; if omitted, the default conversion is the
same as an assignment cast from old data type to new. A USING clause
must be provided if there is no implicit or assignment cast from old to
new type.
"""
See:
https://www.postgresql.org/docs/12/sql-altertable.html
Mark
--
Mark Rotteveel