@@ -119,6 +119,7 @@ export default class PostgresMetaFunctions {
119
119
}
120
120
121
121
const args = currentFunc ! . argument_types . split ( ', ' )
122
+ const identityArgs = currentFunc ! . identity_argument_types
122
123
123
124
const updateDefinitionSql =
124
125
typeof definition === 'string'
@@ -133,40 +134,34 @@ export default class PostgresMetaFunctions {
133
134
)
134
135
: ''
135
136
136
- const retrieveFunctionSql = this . generateRetrieveFunctionSql ( {
137
- schema : currentFunc ! . schema ,
138
- name : currentFunc ! . name ,
139
- args,
140
- } )
141
-
142
137
const updateNameSql =
143
138
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 ) } ;`
147
142
: ''
148
143
149
144
const updateSchemaSql =
150
145
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 ) } ;`
154
149
: ''
155
150
156
151
const sql = `
157
152
DO LANGUAGE plpgsql $$
158
- DECLARE
159
- function record;
160
153
BEGIN
161
154
IF ${ typeof definition === 'string' ? 'TRUE' : 'FALSE' } THEN
162
155
${ updateDefinitionSql }
163
156
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 } )';
170
165
END IF;
171
166
END IF;
172
167
@@ -197,7 +192,7 @@ export default class PostgresMetaFunctions {
197
192
return { data : null , error }
198
193
}
199
194
const sql = `DROP FUNCTION ${ ident ( func ! . schema ) } .${ ident ( func ! . name ) }
200
- (${ func ! . argument_types } )
195
+ (${ func ! . identity_argument_types } )
201
196
${ cascade ? 'CASCADE' : 'RESTRICT' } ;`
202
197
{
203
198
const { error } = await this . query ( sql )
0 commit comments