@@ -44,6 +44,25 @@ select
44
44
pg_get_function_result(f .oid ) as return_type,
45
45
nullif(rt .typrelid ::int8, 0 ) as return_type_relation_id,
46
46
f .proretset as is_set_returning_function,
47
+ case
48
+ when f .proretset and rt .typrelid != 0 and exists (
49
+ select 1 from pg_class c
50
+ where c .oid = rt .typrelid
51
+ -- exclude custom types relation from what is considered a set of table
52
+ and c .relkind in (' r' , ' p' , ' v' , ' m' , ' f' )
53
+ ) then true
54
+ else false
55
+ end as returns_set_of_table,
56
+ case
57
+ when rt .typrelid != 0 then
58
+ (select relname from pg_class where oid = rt .typrelid )
59
+ else null
60
+ end as return_table_name,
61
+ case
62
+ when f .proretset then
63
+ coalesce(f .prorows , 0 ) > 1
64
+ else false
65
+ end as returns_multiple_rows,
47
66
case
48
67
when f .provolatile = ' i' then ' IMMUTABLE'
49
68
when f .provolatile = ' s' then ' STABLE'
76
95
select
77
96
oid ,
78
97
jsonb_agg(jsonb_build_object(
79
- ' mode' , t2 . mode ,
98
+ ' mode' , mode,
80
99
' name' , name,
81
100
' type_id' , type_id,
82
- ' has_default' , has_default
101
+ ' has_default' , has_default,
102
+ ' table_name' , table_name
83
103
)) as args
84
104
from
85
105
(
86
106
select
87
- oid ,
88
- unnest(arg_modes) as mode,
89
- unnest(arg_names) as name,
90
- unnest(arg_types)::int8 as type_id,
91
- unnest(arg_has_defaults) as has_default
92
- from
93
- functions
94
- ) as t1,
95
- lateral (
96
- select
107
+ t1 .oid ,
108
+ t2 .mode ,
109
+ t1 .name ,
110
+ t1 .type_id ,
111
+ t1 .has_default ,
97
112
case
98
- when t1 .mode = ' i' then ' in'
99
- when t1 .mode = ' o' then ' out'
100
- when t1 .mode = ' b' then ' inout'
101
- when t1 .mode = ' v' then ' variadic'
102
- else ' table'
103
- end as mode
104
- ) as t2
113
+ when pt .typrelid != 0 then pc .relname
114
+ else null
115
+ end as table_name
116
+ from
117
+ (
118
+ select
119
+ oid ,
120
+ unnest(arg_modes) as mode,
121
+ unnest(arg_names) as name,
122
+ unnest(arg_types)::int8 as type_id,
123
+ unnest(arg_has_defaults) as has_default
124
+ from
125
+ functions
126
+ ) as t1
127
+ cross join lateral (
128
+ select
129
+ case
130
+ when t1 .mode = ' i' then ' in'
131
+ when t1 .mode = ' o' then ' out'
132
+ when t1 .mode = ' b' then ' inout'
133
+ when t1 .mode = ' v' then ' variadic'
134
+ else ' table'
135
+ end as mode
136
+ ) as t2
137
+ left join pg_type pt on pt .oid = t1 .type_id
138
+ left join pg_class pc on pc .oid = pt .typrelid
139
+ ) sub
105
140
group by
106
- t1 . oid
141
+ oid
107
142
) f_args on f_args .oid = f .oid
0 commit comments