@@ -53,18 +53,39 @@ export default class PostgresMetaFunctions {
5353 return { data : data [ 0 ] , error }
5454 }
5555 } 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+ } `
6081 const { data, error } = await this . query ( sql )
6182 if ( error ) {
6283 return { data, error }
6384 } else if ( data . length === 0 ) {
6485 return {
6586 data : null ,
6687 error : {
67- message : `Cannot find function "${ schema } "."${ name } "(${ argTypes } )` ,
88+ message : `Cannot find function "${ schema } "."${ name } "(${ args . join ( ', ' ) } )` ,
6889 } ,
6990 }
7091 } else {
@@ -84,7 +105,7 @@ export default class PostgresMetaFunctions {
84105 language = 'sql' ,
85106 behavior = 'VOLATILE' ,
86107 security_definer = false ,
87- config_params,
108+ config_params = { } ,
88109 } : {
89110 name : string
90111 schema ?: string
@@ -94,7 +115,7 @@ export default class PostgresMetaFunctions {
94115 language ?: string
95116 behavior ?: 'IMMUTABLE' | 'STABLE' | 'VOLATILE'
96117 security_definer ?: boolean
97- config_params : { [ key : string ] : string }
118+ config_params ? : { [ key : string ] : string }
98119 } ) : Promise < PostgresMetaResult < PostgresFunction > > {
99120 const sql = `
100121 CREATE FUNCTION ${ ident ( schema ) } .${ ident ( name ) } (${ args . join ( ', ' ) } )
@@ -178,10 +199,10 @@ export default class PostgresMetaFunctions {
178199}
179200
180201const enrichedFunctionsSql = `
181- WITH functions AS (
202+ WITH f AS (
182203 ${ functionsSql }
183204 )
184205 SELECT
185- *
186- FROM functions
206+ f. *
207+ FROM f
187208`
0 commit comments