@@ -119,6 +119,7 @@ export default class PostgresMetaFunctions {
119119 }
120120
121121 const args = currentFunc ! . argument_types . split ( ', ' )
122+ const identityArgs = currentFunc ! . identity_argument_types
122123
123124 const updateDefinitionSql =
124125 typeof definition === 'string'
@@ -133,40 +134,34 @@ export default class PostgresMetaFunctions {
133134 )
134135 : ''
135136
136- const retrieveFunctionSql = this . generateRetrieveFunctionSql ( {
137- schema : currentFunc ! . schema ,
138- name : currentFunc ! . name ,
139- args,
140- } )
141-
142137 const updateNameSql =
143138 name && name !== currentFunc ! . name
144- ? `ALTER FUNCTION ${ ident ( currentFunc ! . schema ) } .${ ident ( currentFunc ! . name ) } ( ${
145- currentFunc ! . argument_types
146- } ) RENAME TO ${ ident ( name ) } ;`
139+ ? `ALTER FUNCTION ${ ident ( currentFunc ! . schema ) } .${ ident (
140+ currentFunc ! . name
141+ ) } ( ${ identityArgs } ) RENAME TO ${ ident ( name ) } ;`
147142 : ''
148143
149144 const updateSchemaSql =
150145 schema && schema !== currentFunc ! . schema
151- ? `ALTER FUNCTION ${ ident ( currentFunc ! . schema ) } .${ ident ( name || currentFunc ! . name ) } ( ${
152- currentFunc ! . argument_types
153- } ) SET SCHEMA ${ ident ( schema ) } ;`
146+ ? `ALTER FUNCTION ${ ident ( currentFunc ! . schema ) } .${ ident (
147+ name || currentFunc ! . name
148+ ) } ( ${ identityArgs } ) SET SCHEMA ${ ident ( schema ) } ;`
154149 : ''
155150
156151 const sql = `
157152 DO LANGUAGE plpgsql $$
158- DECLARE
159- function record;
160153 BEGIN
161154 IF ${ typeof definition === 'string' ? 'TRUE' : 'FALSE' } THEN
162155 ${ updateDefinitionSql }
163156
164- ${ retrieveFunctionSql } INTO function;
165-
166- IF function.id != ${ id } THEN
167- RAISE EXCEPTION 'Cannot find function "${ currentFunc ! . schema } "."${ currentFunc ! . name } "(${
168- currentFunc ! . argument_types
169- } )';
157+ IF (
158+ SELECT id
159+ FROM (${ functionsSql } ) AS f
160+ WHERE f.identity_argument_types = ${ literal ( identityArgs ) }
161+ ) != ${ id } THEN
162+ RAISE EXCEPTION 'Cannot find function "${ currentFunc ! . schema } "."${
163+ currentFunc ! . name
164+ } "(${ identityArgs } )';
170165 END IF;
171166 END IF;
172167
@@ -197,7 +192,7 @@ export default class PostgresMetaFunctions {
197192 return { data : null , error }
198193 }
199194 const sql = `DROP FUNCTION ${ ident ( func ! . schema ) } .${ ident ( func ! . name ) }
200- (${ func ! . argument_types } )
195+ (${ func ! . identity_argument_types } )
201196 ${ cascade ? 'CASCADE' : 'RESTRICT' } ;`
202197 {
203198 const { error } = await this . query ( sql )
0 commit comments