Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PG) Support ALTER COLUMN TYPE USING #626

Open
ikkerens opened this issue Mar 24, 2023 · 0 comments · May be fixed by #848
Open

(PG) Support ALTER COLUMN TYPE USING #626

ikkerens opened this issue Mar 24, 2023 · 0 comments · May be fixed by #848

Comments

@ikkerens
Copy link

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant