Describe the feature

Support for "generated" (aka virtual) columns as an independent struct tag option, something along the lines of

struct x {
  A string
  B string
  Whatever string `gorm:"type:varchar;generated:GENERATED ALWAYS AS CONCAT(a,b) STORED;"` // "generated" being the new tag option
}

Burden on the migrations dialector could be low, in that it would just take the string as passed to the generated tag and apply it to the query. However, when mutating an existing table, it would not trigger an alter statement on the column - which is what breaks the work around (described below).

Motivation

Previously this could be accomplished by appending to the type:... tag

struct x {
  A string
  B string
  Whatever string `gorm:"type:varchar GENERATED ALWAYS AS CONCAT(a,b) STORED;"`
}

but with the changes released in 1.20.9 (https://github.com/go-gorm/gorm/commit/59730417aabd5b510d66d9d923d265a6fc0195a0), this now breaks, as its now detected as a change that should trigger an alter statement, and that will fail (at least with postgres). Supporting GENERATED/VIRTUAL columns is a super nice to have feature that would be awesome to have w/ GORM, and feels like something that would be deserving of its own "instruction" in GORM's supported set of tags, as opposed to a hack that just happens to work by appending to the type declaration.

Related Issues

Unknown; but this change (https://github.com/go-gorm/gorm/commit/59730417aabd5b510d66d9d923d265a6fc0195a0) caused the previous workaround to now work anymore, so filing this as a full fledged feature request.

Comment From: jinzhu

https://gorm.io/docs/create.html#Default-Values

There is an example for how to use GENERATED columns, and from the commit https://github.com/go-gorm/gorm/commit/59730417aabd5b510d66d9d923d265a6fc0195a0, I don't think this will cause a alter SQL for your struct, if you can reproduce this, could you submit a playground PR link?