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

How to customise mutableColumns to read-only generated columns in PostgreSQL? #209

Closed
rangzen opened this issue Jan 25, 2023 · 6 comments · Fixed by #210
Closed

How to customise mutableColumns to read-only generated columns in PostgreSQL? #209

rangzen opened this issue Jan 25, 2023 · 6 comments · Fixed by #210

Comments

@rangzen
Copy link
Contributor

rangzen commented Jan 25, 2023

Hello,
We use generated columns with PostgreSQL, see Generated Columns.
We would like to exclude these columns from the generated mutableColumns list.
Can we use something like Generator customization?
Is this possible without adding fields to metadata.Table or metadata.Column? Without changing DefaultTableModel(tableMetaData metadata.Table) TableModel to an interface to reimplement (t table) MutableColumns() []Column?
Thank you!

@go-jet
Copy link
Owner

go-jet commented Jan 26, 2023

Hi @rangzen,

Currently it is not possible to exclude columns from AllColumns or MutableColumns lists.
Workaround is to create new ColumnLists and use those instead. For instance:

var PeopleAllColumns     = People.AllColumns.Except(People.HeightIn)
var PeopleMutableColumns = People.MutableColumns.Except(People.HeightIn)

In terms of implementation, I suppose adding a new `Skip' flag would be enough to signal that the column should not appear in table sql builder struct.

@go-jet go-jet pinned this issue Jan 26, 2023
@go-jet go-jet unpinned this issue Jan 26, 2023
@mlaflamm
Copy link
Contributor

I just want to clarify that Postgres generated columns are read only. The goal would be to keep them in AllColumns and the table struct but to exclude them from MutableColumns.

@go-jet
Copy link
Owner

go-jet commented Jan 28, 2023

Aha, I see. In that case implementation can be simplified. We can retrieve additional column is_generated from information_schema.columns and then in MutableColumns() []Column filter out primary key and generated columns.

The only concern is this might affect existing users. But I think it should be fine, because generated columns can't be used in either insert or update statements, so existing users are probably already excluding generated columns.

@rangzen
Copy link
Contributor Author

rangzen commented Jan 30, 2023

@go-jet PR and data pushed. Not sure how you deal with the submodule.

@rangzen
Copy link
Contributor Author

rangzen commented Jan 30, 2023

Yep, CircleCI need first the link to the data submodule
panic: open ./testdata/init/cockroach/test_generated.sql: no such file or directory

@go-jet
Copy link
Owner

go-jet commented Jan 30, 2023

Yeah, when jet-test-data PR is merged, jet PR build will be fixed. For local development you can use makefile command - make checkout-testdata, in tests directory, to pull latest submodule master commit.

@go-jet go-jet closed this as completed in a4191b4 Feb 1, 2023
@go-jet go-jet added this to the Version 2.10.0 milestone Apr 17, 2023
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 a pull request may close this issue.

3 participants