GeezerVison is showing github.com — SchemaDiffTool: schema sync script error when changing output data type or OUT argument list in function · Issue #6652 · pgadmin-org/pgadmin4
SchemaDiffTool: schema sync script error when changing output data type or OUT argument list in function #6652DescriptionChanging the output data type or OUT argument list in the source schema function causes the target schema synchronization script to fail. This change is not considered an overload in PostgreSQL and cannot be applied until the function is removed.
Problem reproduction:
Scheme source:
CREATE OR REPLACE FUNCTION class_del(
iid bigint)
RETURNS void
LANGUAGE 'plpgsql'
COST 100
VOLATILE SECURITY DEFINER PARALLEL UNSAFE
AS $BODY$
--source FUNCTION new API
DECLARE
action_state character varying DEFAULT 'none';
BEGIN
---Code Function
--************************************************************
----------------THROW EXCEPTION
--************************************************************
IF (action_state <> 'action_allowed') THEN
RAISE EXCEPTION 'Error message';
END IF;
END;
$BODY$;
Scheme target:
CREATE OR REPLACE FUNCTION class_del(
iid bigint,
OUT Result INT)
RETURNS INT
LANGUAGE 'plpgsql'
COST 100
VOLATILE SECURITY DEFINER PARALLEL UNSAFE
AS $BODY$
--target FUNCTION old API
DECLARE
action_state character varying DEFAULT 'none';
BEGIN
Result = 0;
---Code Function
--************************************************************
----------------THROW EXCEPTION
--************************************************************
IF (action_state <> 'action_allowed') THEN
Result = 144; --Set error code
END IF;
END;
$BODY$;
PS:
I do not think that this can be separated into a separate topic. I want to draw your attention to the fact that the state of the selection filter does not affect the script generator in any way and has a purely cosmetic (ostentatious) use. If this behavior could be controlled, the severity of the problem would decrease. I have more than 700 functions in the API and I can only edit the full script in third-party editors, since yours just freezes (on my computer). Applying a filter would allow me to step-by-step sync by changing the accepted sync strategy. Activityakshay-joshi commented on Aug 14, 2023 @firstDismay
If I understood correctly I have run the above-given query and then run the schema diff which is showing two objects, one is source only and another is target only because of function overloading.

The above behavior is expected because for schema diff both the functions are different. Run the below test case:
Source function:
CREATE OR REPLACE FUNCTION source.test_sum(a bigint, b bigint)
RETURNS bigint
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
BEGIN
RETURN a + b;
END;
$BODY$;
Target Function:
CREATE OR REPLACE FUNCTION target.test_sum(a bigint, b bigint)
RETURNS double precision
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
BEGIN
RETURN a + b;
END;
$BODY$;
In short, if the function's return type is different than schema diff will add the 'DROP FUNCTION..' syntax. firstDismay commented on Aug 15, 2023 @akshay-joshi
I agree with this behavior. But drop will be added after create. If the input signatures are identical (out or return type changes), this sequence is erroneous. The script will not run until you swap drop and create for my example. akshay-joshi commented on Aug 16, 2023 @firstDismay
I am unable to reproduce that, in my case DROP statement is before the CREATE.
 firstDismay commented on Aug 16, 2023 @akshay-joshi
I didn't use this form. I clicked the create script button for all the differences in the functions. For version 7.4, I had all drop function operations at the end. I swapped places manually. After that, everything was successful. I don't have access to the computer now I can't check your option. I have more than 700 functions, one does not suit me. akshay-joshi commented on Aug 16, 2023 @firstDismay
I am still not able to reproduce. I have created 7 identical functions with different names and return types in source and target. I selected all of them and click on generate script button.

 firstDismay commented on Aug 20, 2023 @akshay-joshi
I don't see the behavior you describe when adding a DROP is needed. I changed the output type of the function from void to record. Added two OUT variables (on the target side). Conducted a comparison and received a synchronization script:
CREATE OR REPLACE FUNCTION bpd.class_prop_del(
iid bigint)
RETURNS void
LANGUAGE 'plpgsql'
COST 100
VOLATILE SECURITY DEFINER PARALLEL UNSAFE
SET search_path=bpd, "int", err
AS $BODY$
------
CREATE OR REPLACE FUNCTION bpd.class_del(
iid bigint)
RETURNS void
LANGUAGE 'plpgsql'
COST 100
VOLATILE SECURITY DEFINER PARALLEL UNSAFE
SET search_path=bpd, err
AS $BODY$
------
DROP FUNCTION IF EXISTS bpd.class_prop_del(iid bigint, OUT result bigint, OUT descerr text);
DROP FUNCTION IF EXISTS bpd.class_del(iid bigint, OUT result bigint, OUT descerr text);
This script cannot work:
ERROR: You cannot change the return type of an existing function
HINT: DROP FUNCTION bpd.class_prop_del(bigint) first.
ERROR: You cannot change the return type of an existing function
SQL state: 42P13
PS:
I use the "Generate Script" button. pgAdmin version 7.5. PostgreSQL version 14.9. akshay-joshi commented on Aug 25, 2023 @firstDismay
If I understand correctly schema diff is showing two objects one is source only and another is target only for functions "class_prop_del" and "class_del" just because their signature is different(Function overloading). When you select them it will create the "CREATE OR REPLACE" script and then the "DROP" statement.
If the above is correct then it's been difficult to fix the issue, as schema diff treated both the functions as separate functions so on your selection it will create the statement. I suggest you apply the 'Target Only' filter which will create the 'DROP syntax' for all 700 functions. Select all of them and click on the "Generate script" button.
Then apply filter 'Source Only', select all the functions, and click on the "Generate script" button.
 firstDismay commented on Aug 26, 2023 @akshay-joshi
From the point of view of PostgreSQL, these functions are equivalent. The signature of the function is determined only by the arguments of the IN, INOUT and VARIADIC.
proargtypes - An array of the data types of the function arguments. This includes only input arguments (including INOUT and VARIADIC arguments), and thus represents the call signature of the function.
Based on these considerations, you can install DROP before CREATE. akshay-joshi commented on Aug 28, 2023 @firstDismay
This is very complex for Schema Diff to compare considering all the scenarios. Schema Diff compares the functions with Name and Argument. I am keeping it as a Low Priority issue. firstDismay commented on Aug 28, 2023 @akshay-joshi
I do not insist on the seriousness of the problem. I'm just pointing out that your interpretation of overloading doesn't follow PostgreSQL's call signature principles, which is the basis for the divergence in defining function equivalence, which leads to separate processing when signatures differ in areas not considered by PostgreSQL. dpage commented on Oct 15, 2026
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|