@@ -53,18 +53,39 @@ export default class PostgresMetaFunctions {
53
53
return { data : data [ 0 ] , error }
54
54
}
55
55
} else if ( name && schema && args ) {
56
- const argTypes = args . join ( ', ' )
57
- const sql = `${ enrichedFunctionsSql } WHERE schema = ${ literal ( schema ) } AND name = ${ literal (
58
- name
59
- ) } AND argument_types = ${ literal ( argTypes ) } ;`
56
+ const sql = `${ enrichedFunctionsSql } JOIN pg_proc AS p ON id = p.oid WHERE schema = ${ literal (
57
+ schema
58
+ ) } AND name = ${ literal ( name ) } AND p.proargtypes::text = ${
59
+ args . length
60
+ ? `(
61
+ SELECT STRING_AGG(type_oid::text, ' ') FROM (
62
+ SELECT (
63
+ split_args.arr[
64
+ array_length(
65
+ split_args.arr,
66
+ 1
67
+ )
68
+ ]::regtype::oid
69
+ ) AS type_oid FROM (
70
+ SELECT STRING_TO_ARRAY(
71
+ UNNEST(
72
+ ARRAY[${ args . map ( literal ) } ]
73
+ ),
74
+ ' '
75
+ ) AS arr
76
+ ) AS split_args
77
+ ) args
78
+ );`
79
+ : literal ( '' )
80
+ } `
60
81
const { data, error } = await this . query ( sql )
61
82
if ( error ) {
62
83
return { data, error }
63
84
} else if ( data . length === 0 ) {
64
85
return {
65
86
data : null ,
66
87
error : {
67
- message : `Cannot find function "${ schema } "."${ name } "(${ argTypes } )` ,
88
+ message : `Cannot find function "${ schema } "."${ name } "(${ args . join ( ', ' ) } )` ,
68
89
} ,
69
90
}
70
91
} else {
@@ -84,7 +105,7 @@ export default class PostgresMetaFunctions {
84
105
language = 'sql' ,
85
106
behavior = 'VOLATILE' ,
86
107
security_definer = false ,
87
- config_params,
108
+ config_params = { } ,
88
109
} : {
89
110
name : string
90
111
schema ?: string
@@ -94,7 +115,7 @@ export default class PostgresMetaFunctions {
94
115
language ?: string
95
116
behavior ?: 'IMMUTABLE' | 'STABLE' | 'VOLATILE'
96
117
security_definer ?: boolean
97
- config_params : { [ key : string ] : string }
118
+ config_params ? : { [ key : string ] : string }
98
119
} ) : Promise < PostgresMetaResult < PostgresFunction > > {
99
120
const sql = `
100
121
CREATE FUNCTION ${ ident ( schema ) } .${ ident ( name ) } (${ args . join ( ', ' ) } )
@@ -178,10 +199,10 @@ export default class PostgresMetaFunctions {
178
199
}
179
200
180
201
const enrichedFunctionsSql = `
181
- WITH functions AS (
202
+ WITH f AS (
182
203
${ functionsSql }
183
204
)
184
205
SELECT
185
- *
186
- FROM functions
206
+ f. *
207
+ FROM f
187
208
`
0 commit comments