Add support for generated columns in PostgreSQL (Redux)#41856
Add support for generated columns in PostgreSQL (Redux)#41856matthewd merged 2 commits intorails:mainfrom
Conversation
There was a problem hiding this comment.
This is the only place where I disagree with some of the given feedback regarding future proofing (e.g. #39368 (comment)). In PostgreSQL 14 there is still no VIRTUAL support planed.
In my opinion it's better to provide a precise error message rather than adding support for something that may not happen anytime soon (and maybe even create incorrect SQL statements in the process).
Note: This only affects migration support. Reading any type of virtual column is supported.
6e1b337 to
4233c97
Compare
89d5577 to
249e327
Compare
249e327 to
64fd666
Compare
|
We've been running this PR as a monkeypatch for a few months without issues. It would be great to have this merged! |
|
Any chances that this PR could fix this issue? #42469 |
|
Yeah, with time marching on, I'm feeling more inclined towards the current implementation's conservatism: Postgres will presumably implement virtual columns at some point in the future, but our ability to predict exactly what that'll look like is limited. Better to make support available for the existing feature, and leave an attempt to use the still-theoretical future behaviour to fail in a clear way (which is no better or worse than how it would already fail today if we continue to not ship this PR). |
The current implementation (rails#41856) required `stored: true` to be passed when using `t.virtual()` https://github.com/rails/rails/pull/41856/files#diff-5b1b920fc3bebbb1d4c144b302603e5003a1d9e5a493e3234bf764b9e26fbe30R68-R75
|
Apologies for commenting, did this make it into Rails 7? I was looking through changelogs and couldn't find anything conclusive. |
|
We're not quite on Rails 7 yet, so I back-ported this to a gem for Rails 6.1.5 in the hopes that it may be useful for others as well: |
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
PostgreSQL 18 Beta 1 introduces virtual (not persisted) generated columns, which are now the default unless the STORED option is explicitly specified. Rails previously supported only stored generated columns on PostgreSQL 12+, via rails#41856, as only stored generated columns were supported by PostgreSQL at the time. This commit adds support for virtual generated columns on PostgreSQL 18 and later: - `t.virtual ... stored: false` now generates virtual generated columns. - Omitting `stored:` also creates virtual generated columns on PostgreSQL 18+. - On PostgreSQL < 18, specifying `stored: false` or omitting `stored:` raises ArgumentError. consistent with the existing behavior in earlier Rails versions. Reference: PostgreSQL 18 release notes https://www.postgresql.org/docs/18/release-18.html > Allow generated columns to be virtual, and make them the default > (Peter Eisentraut, Jian He, Richard Guo, Dean Rasheed) > > Virtual generated columns generate their values when the columns are read, not written. > The write behavior can still be specified via the STORED option. Source: - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=83ea6c540 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cdc168ad4 - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=1e4351af3 Co-authored-by: fatkodima <[email protected]> Co-authored-by: Ryuta Kamizono <[email protected]>
Basically this is a friendly takeover of #39368 which adds support for generated columns in PostgreSQL (which are available since PostgreSQL 12).
Sadly there was no progress since July 2020.
I kept @fanfilmu as author and just rebased onto current main and incorporated most of the given feedback.