Skip to content

fix(mysql)!: full MODIFY COLUMN support.#7562

Open
burnison wants to merge 1 commit intotobymao:mainfrom
burnison:mysql_alter_modify
Open

fix(mysql)!: full MODIFY COLUMN support.#7562
burnison wants to merge 1 commit intotobymao:mainfrom
burnison:mysql_alter_modify

Conversation

@burnison
Copy link
Copy Markdown
Contributor

@burnison burnison commented Apr 25, 2026

The semantics of MODIFY COLUMN in MySQL are not the same as ALTER COLUMN, but have been treated so since #3189. The two ALTER TABLE expressions are fundamentally incompatible:

  | MODIFY [COLUMN] col_name column_definition
        [FIRST | AFTER col_name]

  | ALTER [COLUMN] col_name {
        SET DEFAULT {literal | (expr)}
      | SET {VISIBLE | INVISIBLE}
      | DROP DEFAULT
    }

Most importantly, the MODIFY COLUMN syntax takes a full column_definition and column position. The actual execution behaviour of MODIFY does not merge the column definition, but completely redefines it.

When deciding what approach to take for implementation, I evaluated 3 approaches:

  • Adding a column_definition to AlterColumn, but this would be parallel to the other attributes leading to surprising syntax.

  • Similarly, adding constraints to AlterColumn, which, again, would lead to surprising, inconsistent outcomes.

  • This implementation, a dedicated ModifyColumn, which potentially breaks existing MODIFY COLUMN deployments that might depend on it parsing to AlterColumn.

This breaking change is defensible, however, in that MODIFY COLUMN c DROP DEFAULT isn't valid syntax in MySQL. I'm led to believe the behaviour of existing deployments would likely be questionable if not broken (example: I had been working around it for more than a year by rewriting to ADD COLUMN).

The semantics of `MODIFY COLUMN` in MySQL are not the same as `ALTER
COLUMN`, but have been treated so since tobymao#3189. The two expressions are
fundamentally incompatible:

```
  | MODIFY [COLUMN] col_name column_definition
        [FIRST | AFTER col_name]

  | ALTER [COLUMN] col_name {
        SET DEFAULT {literal | (expr)}
      | SET {VISIBLE | INVISIBLE}
      | DROP DEFAULT
    }
```

Most importantly, the `MODIFY COLUMN` syntax takes a full
`column_definition` and column position. The actual execution behaviour
of `MODIFY` does not actually merge the column definition, but
completely redefines it.

When deciding what approach to take for implementation, I evaluated 3
approaches:

* Adding a `column_definition` to `AlterColumn`, but this would be
  parallel to the other attributes leading to surprising syntax.

* Similarly, adding `constraints` to `AlterColumn`, which, again, would
  lead to surprising, inconsistent outcomes.

* This implementation, a dedicated `ModifyColumn`, which changes
  existing `MODIFY COLUMN` deployments that depend on `AlterColumn`.

This breaking change are defensible, however, in that `MODIFY COLUMN c
DROP DEFAULT` isn't valid syntax in MySQL, so the behaviour of existing
deployments would likely be questionable.
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 this pull request may close these issues.

1 participant