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

Not-nullable fields in materialized view #29

Closed
shiro opened this issue Aug 15, 2020 · 4 comments
Closed

Not-nullable fields in materialized view #29

shiro opened this issue Aug 15, 2020 · 4 comments

Comments

@shiro
Copy link

shiro commented Aug 15, 2020

In order for the TS types to not be marked as nullable the table constraints are looked up as far as I understand.
However when dealing with materialized views there is no way to mark a field as non-nullable.

I understand that there is no way to guarantee that there is no null values in the materialized view, however as a developer I often know that based on how the view is generated.

I just wanted to ask if there is any way to mark a field as not nullable explicitly rather than relying on the DB introspection, since it means I have to manually rewrite most type definitions on materialized views which makes the use of this tool pointless for the use-case.

Thanks for the help.

@akheron
Copy link
Owner

akheron commented Aug 16, 2020

Good point! Currently there’s no way to override what sqltyper has inferred. What do you think would be the best way mark the fields non-billable?

@shiro
Copy link
Author

shiro commented Aug 16, 2020

I don't know of any way to annotate selected fields using PostgreSQL's syntax.
There's probably not that many ways to do it, pretty much the only way I can think of is putting a code block in front of the SQL statement and annotate types in some way (like a docblock for example).

For example:

-- @type a NOT NULL
-- @type b integer NOT NULL
SELECT a, b, c FROM t;

Would allow to keep a's inferred type and just modify nullability constraints while staying flexible about future explicit type modification such as setting the type explicitly as well.
It's just a suggestion, that or any other way would work IMO.

@akheron
Copy link
Owner

akheron commented Aug 16, 2020

Seems you can get the underlying query of a (materialized) view, at least using the pg_get_viewdef function, and so it would be possible to run the analysis on that query instead.

@akheron
Copy link
Owner

akheron commented Sep 11, 2020

Created a new issue to track this: #43

@akheron akheron closed this as completed Sep 11, 2020
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

2 participants