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

Support setting visibility on ALTER COLUMN. #4809

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

burnison
Copy link
Contributor

MySQL 8.0 introduced the ability to hide and unhide columns. Columns can be hidden in a CREATE TABLE statement (currently unimplemented in sqlglot) and can be subsequently changed with an ALTER TABLE syntax: ALTER COLUMN x SET {VISIBLE|INVISIBLE}.

This commit adds support for column hiding through the ALTER TABLE syntax. However, it does so in a MySQL-specific way. Other RDBMSs have similar support for column hiding, but implement it slightly differently:

  • Oracle uses MODIFY x INVISIBLE
  • DB2 uses ALTER x t IMPLICITLY HIDDEN
  • SQLServer uses ALTER x ADD HIDDEN

As there is no other dialect in sqlglot that implements invisibility, and because the parser currently maintains other dialect-specific implementations, I wasn't sure if the amount of effort to refactor the parser to be dialect-agnostic was worthwhile for this specific change (I couldn't find a similar pattern). If you disagree, I would be willing to attempt the refactor, though, I would appreciate some suggestions on how it could be done, as it was not immediately apparent.

MySQL 8.0 introduced the [ability to hide and unhide columns]. Columns
can be hidden in a `CREATE TABLE` statement (currently unimplemented in
`sqlglot`) and can be subsequently changed with an `ALTER TABLE` syntax:
`ALTER COLUMN x SET {VISIBLE|INVISIBLE}`.

This commit adds support for column hiding through the `ALTER TABLE`
syntax. However, it does so in a MySQL-specific way. Other RDBMSs have
similar support for column hiding, but implement it slightly
differently:

* Oracle uses `MODIFY x INVISIBLE`
* DB2 uses `ALTER x t IMPLICITLY HIDDEN`
* SQLServer uses `ALTER COLUMN x ADD HIDDEN`

As there is no other dialect in `sqlglot` that implements invisibility,
and because the parser currently maintains dialect-specific
implementations, I wasn't sure if the amount of effort to refactor the
parser was worthwhile for this change.

[ability to hide and unhide columns]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@georgesittas georgesittas merged commit c5bf122 into tobymao:main Feb 27, 2025
7 checks passed
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.

2 participants