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

Materialized view columns #39

Open
hiendaovinh opened this issue Mar 31, 2023 · 9 comments
Open

Materialized view columns #39

hiendaovinh opened this issue Mar 31, 2023 · 9 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@hiendaovinh
Copy link

Hi,
With the given schema: https://github.com/stephenafamo/bob/blob/main/gen/bobgen-psql/driver/testdatabase.sql, I think it's reasonable to expect bob to generate type_monsters_mv columns just like type_monsters_v but it doesn't. Is it expected behavior?
https://github.com/stephenafamo/bob/blob/main/gen/bobgen-psql/driver/psql.golden.json#L2228-L2238
Thank you.

@stephenafamo stephenafamo added help wanted Extra attention is needed enhancement New feature or request labels Mar 31, 2023
@stephenafamo
Copy link
Owner

It would be a reasonable expectation, I just haven't gotten to it yet.

Because materialized views are not part of the SQL specification, Postgres does not include information about them in the information_schema.views table.
So querying for details of a materialized view needs a whole new query in the driver.

I'm not sure how soon I'll get to this myself. Of course, I'll be happy to review a PR for this 😁.

@hiendaovinh
Copy link
Author

I'll be happy to work on this. Let me test pg_get_viewdef and pg_matviews and see what I can do.

@hiendaovinh
Copy link
Author

pg_attribute holds enough information on matview columns. We just need to find a way to map & normalize them to information_schema.

@stephenafamo
Copy link
Owner

If you can implement this TableDetails function for materialized views, then the rest would be a breeze.

@hiendaovinh
Copy link
Author

hiendaovinh commented Mar 31, 2023

Yes I'm working on it.

pg_attribute & information_schema.columns

  • column_name: attname
  • column_type (Currently returned actual enum "workday" name instead of "ENUM")
  • udt_schema
  • udt_name
  • array_type
  • domain_name
  • column_default
  • column_comment
  • is_nullable: attnotnull
  • is_generated: attgenerated
  • is_identity: attidentity

Will comeback and update this.

@hiendaovinh
Copy link
Author

@stephenafamo
Copy link
Owner

Another place to look is in SQLBoiler. https://github.com/volatiletech/sqlboiler/blob/master/drivers/sqlboiler-psql/driver/psql.go#LL392C2-L485

While not expecting exactly the same columns, it is quite similar since Bob was heavily inspired by SQLBoiler.

@stephenafamo
Copy link
Owner

How's it going? @hiendaovinh

@hiendaovinh
Copy link
Author

Sorry, there's no further progress yet because I was kind of busy last week. Will come back this week sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants