cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.13k stars 3.81k forks source link

sql: support `DROP EXPRESSION` syntax #75284

Open ajwerner opened 2 years ago

ajwerner commented 2 years ago

Is your feature request related to a problem? Please describe. Before postgres version 13, there was no way to tell postgres to stop using a default expression for a stored, generated column. In 13, they added DROP EXPRESSION syntax. Cockroach has long had DROP STORED syntax, which is, well, confusing and hard to discover.

This form turns a stored generated column into a normal base column. Existing data in the columns is retained, but future changes will no longer apply the generation expression.

If DROP EXPRESSION IF EXISTS is specified and the column is not a stored generated column, no error is thrown. In this case a notice is issued instead.

https://www.postgresql.org/docs/13/sql-altertable.html

Describe the solution you'd like

Support DROP EXPRESSION like we today support DROP STORED.

Jira issue: CRDB-12539

lin-crl commented 2 years ago

Thank you Andrew for filing this issue! It'll be nice to add it to \h ALTER TABLE when we make this change.

techytoes commented 2 years ago

@ajwerner @rafiss If it's okay I would like to work on this issue. Thanks!

ajwerner commented 2 years ago

Go for it! It should be a good first issue. We don't generally assign issues to community members but we gladly accept PRs.

techytoes commented 2 years ago

@ajwerner I made the necessary changes in alter_table.go and stmt.go but it seems like the DROP EXPRESSION is still not recognized. Even after running make the code isn't generated for DROP EXPRESSION. I am kind of stuck on this and would be great if you help.

Also, where can I read more about the stringer command? Thanks!

ajwerner commented 2 years ago

Did you update the syntax in sql.y?

techytoes commented 2 years ago

@ajwerner I somehow missed changes for this. It's working now. Thanks!