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

Derived/Computed Columns #1078

Closed
parsonsmatt opened this issue Apr 20, 2020 · 1 comment
Closed

Derived/Computed Columns #1078

parsonsmatt opened this issue Apr 20, 2020 · 1 comment

Comments

@parsonsmatt
Copy link
Collaborator

Postgres 12 supports generated columns. We should be able to support these.

The current ability to support is pretty limited. Per the Postgres docs,

A generated column cannot be written to directly. In INSERT or UPDATE commands, a value cannot be specified for a generated column, but the keyword DEFAULT may be specified.

So if we have a model definition like:

User
    name Text
    birthday Day
    age Int GeneratedAsDifferenceFromAgeToBirthday Virtual

Then we would currently need to provide some dummy value to this field when performing writes/updates, like:

insert User 
    { userName = "Bob"
    , userBirthday = fromGregorian 1988 29 09
    , userAge = 123456789
    }

The inserting code would see that the column is generated and use DEFAULT instead of a value.

The design in #1037 makes this trivial - generated columns would be present on the full entity, while New entity would not have them, and (importantly) Partial entity would not either.

@parsonsmatt
Copy link
Collaborator Author

Support for this was added in 2.11, thanks to #1122

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

No branches or pull requests

1 participant