-
-
Notifications
You must be signed in to change notification settings - Fork 151
feat(typegen): add functions setof type introspection #971
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
Open
avallete
wants to merge
5
commits into
master
Choose a base branch
from
feat/add-functions-setof-type-introspection-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,333
−300
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64a1afc
feat(typegen): add setof function type introspection
avallete 1bd2b30
Merge branch 'master' into feat/add-functions-setof-type-introspectio…
avallete 3bb1b45
chore: update snapshots
avallete 6b8c753
chore: unify sort and dedup loops
avallete c22c830
chore: remove duplicate sort
avallete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,25 @@ select | |
pg_get_function_result(f.oid) as return_type, | ||
nullif(rt.typrelid::int8, 0) as return_type_relation_id, | ||
f.proretset as is_set_returning_function, | ||
case | ||
when f.proretset and rt.typrelid != 0 and exists ( | ||
select 1 from pg_class c | ||
where c.oid = rt.typrelid | ||
-- exclude custom types relation from what is considered a set of table | ||
and c.relkind in ('r', 'p', 'v', 'm', 'f') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment All possible function embeding relations: r | ordinary table |
||
) then true | ||
else false | ||
end as returns_set_of_table, | ||
case | ||
when rt.typrelid != 0 then | ||
(select relname from pg_class where oid = rt.typrelid) | ||
else null | ||
end as return_table_name, | ||
case | ||
when f.proretset then | ||
coalesce(f.prorows, 0) > 1 | ||
else false | ||
end as returns_multiple_rows, | ||
case | ||
when f.provolatile = 'i' then 'IMMUTABLE' | ||
when f.provolatile = 's' then 'STABLE' | ||
|
@@ -76,32 +95,48 @@ from | |
select | ||
oid, | ||
jsonb_agg(jsonb_build_object( | ||
'mode', t2.mode, | ||
'mode', mode, | ||
'name', name, | ||
'type_id', type_id, | ||
'has_default', has_default | ||
'has_default', has_default, | ||
'table_name', table_name | ||
)) as args | ||
from | ||
( | ||
select | ||
oid, | ||
unnest(arg_modes) as mode, | ||
unnest(arg_names) as name, | ||
unnest(arg_types)::int8 as type_id, | ||
unnest(arg_has_defaults) as has_default | ||
from | ||
functions | ||
) as t1, | ||
lateral ( | ||
select | ||
t1.oid, | ||
t2.mode, | ||
t1.name, | ||
t1.type_id, | ||
t1.has_default, | ||
case | ||
when t1.mode = 'i' then 'in' | ||
when t1.mode = 'o' then 'out' | ||
when t1.mode = 'b' then 'inout' | ||
when t1.mode = 'v' then 'variadic' | ||
else 'table' | ||
end as mode | ||
) as t2 | ||
when pt.typrelid != 0 then pc.relname | ||
else null | ||
end as table_name | ||
from | ||
( | ||
select | ||
oid, | ||
unnest(arg_modes) as mode, | ||
unnest(arg_names) as name, | ||
unnest(arg_types)::int8 as type_id, | ||
unnest(arg_has_defaults) as has_default | ||
from | ||
functions | ||
) as t1 | ||
cross join lateral ( | ||
select | ||
case | ||
when t1.mode = 'i' then 'in' | ||
when t1.mode = 'o' then 'out' | ||
when t1.mode = 'b' then 'inout' | ||
when t1.mode = 'v' then 'variadic' | ||
else 'table' | ||
end as mode | ||
) as t2 | ||
left join pg_type pt on pt.oid = t1.type_id | ||
left join pg_class pc on pc.oid = pt.typrelid | ||
) sub | ||
group by | ||
t1.oid | ||
oid | ||
) f_args on f_args.oid = f.oid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
Include functions that loops to a view for embedded functions.