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

Functions returning view type must have pkey (et.al.) #483

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

olirice
Copy link
Contributor

@olirice olirice commented Jan 3, 2024

When a function returns a view's type and that view is selectable but does not have a primary key (a requirement to be present in the schema), the function contains an invalid type reference. This PR resolves that issue by requiring that all the requirements for a table/view to be included in the __Schema are met before allowing it to be returned by a function in the __Schema

This is another attempt at #477 which mirrors the logic in __Schema exactly rather than checking a subset of requirements.

The intended goal is to avoid invalid references caused by functions returning types that aren't present in the schema.


Resolves #481

@olirice olirice requested a review from imor January 3, 2024 21:54
@@ -807,7 +807,7 @@ begin;
rollback to savepoint a;

create table account(
id int,
id int primary key,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this to make the test valid since we require primary keys

create function returns_null_account()
returns account language sql stable
as $$ select id, email, name from account where id = 9; $$;

insert into account(id, email, name)
values
(1, '[email protected]', 'aardvark'),--all columns non-null
(2, '[email protected]', null),--mixed: some null, some non-null
(null, null, null);--all columns null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after adding the pkey constraint, this record is no longer valid.

Since require a pkey I don't think it's necessary/possible to test for this case because can't happen. right?

@imor imor merged commit fee0c26 into master Jan 4, 2024
4 checks passed
@imor imor deleted the or/plug-view-function-type-hole branch January 4, 2024 05:59
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 this pull request may close these issues.

Function returns set-of view fails introspection if view does not define primary key
2 participants