sea-query
sea-query copied to clipboard
(PG) Support ALTER COLUMN TYPE USING
Motivation
Currently it is not possible in migrations to add a USING clause to changing the column type that have no direct available cast, without the use of writing SQL queries myself. The example that I happened to come across myself is changing the type of a column from bigint to bigint[] (array).
The postgres query to achieve this is as follows:
ALTER TABLE table_name ALTER column_name TYPE bigint[] USING array[column_name];
Proposed Solutions
Something like:
manager.alter_table(
Table::alter()
.table(type::Table)
.modify_column(ColumnDef::new(type::ColumnName).array(Type::BigInteger, SimpleExpr::Using(type::ColumnName)))
.to_owned());
Additional Information
I was requested to open this issue in a Discord thread titled "(PG) Change type of column to array of the previous type."