GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #6652

New issue
Copy link
New issue
Copy link
Closed
Closed
SchemaDiffTool: schema sync script error when changing output data type or OUT argument list in function#6652
Copy link
Labels
Bug

Description

@firstDismay
firstDismay
opened on Aug 3, 2023
Issue body actions

Changing 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.

Activity

  1. akshay-joshi
    added this to Not Refinedon Aug 4, 2023
  2. adityatoshniwal
    assigned
    akshay-joshi
    on Aug 11, 2023
  3. akshay-joshi
    assigned
    firstDismay
    and unassigned
    akshay-joshi
    on Aug 14, 2023
  4. akshay-joshi commented on Aug 14, 2023

    @akshay-joshi
    akshay-joshi
    on Aug 14, 2023
    Contributor
    More actions

    @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.
    Screenshot 2023-08-14 at 1 36 17 PM

    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.

  5. firstDismay commented on Aug 15, 2023

    @firstDismay
    firstDismay
    on Aug 15, 2023
    Author
    More actions

    @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.

  6. akshay-joshi commented on Aug 16, 2023

    @akshay-joshi
    akshay-joshi
    on Aug 16, 2023
    Contributor
    More actions

    @firstDismay

    I am unable to reproduce that, in my case DROP statement is before the CREATE.
    Screenshot 2023-08-16 at 12 31 39 PM

  7. firstDismay commented on Aug 16, 2023

    @firstDismay
    firstDismay
    on Aug 16, 2023
    Author
    More actions

    @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.

  8. akshay-joshi commented on Aug 16, 2023

    @akshay-joshi
    akshay-joshi
    on Aug 16, 2023
    Contributor
    More actions

    @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.
    Screenshot 2023-08-16 at 1 11 33 PM
    Screenshot 2023-08-16 at 1 11 50 PM

  9. firstDismay commented on Aug 20, 2023

    @firstDismay
    firstDismay
    on Aug 20, 2023
    Author
    More actions

    @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.

  10. akshay-joshi
    assigned
    akshay-joshi
    and unassigned
    firstDismay
    and
    akshay-joshi
    on Aug 21, 2023
  11. akshay-joshi commented on Aug 25, 2023

    @akshay-joshi
    akshay-joshi
    on Aug 25, 2023
    Contributor
    More actions

    @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.

    Screenshot 2023-08-25 at 1 40 26 PM
  12. akshay-joshi
    assigned
    firstDismay
    on Aug 25, 2023
  13. firstDismay commented on Aug 26, 2023

    @firstDismay
    firstDismay
    on Aug 26, 2023
    Author
    More actions

    @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.

  14. akshay-joshi
    added this to Ready for Sprint Bugs and removed this from Not Refinedon Aug 28, 2023
  15. akshay-joshi
    unassigned
    firstDismay
    on Aug 28, 2023
  16. akshay-joshi commented on Aug 28, 2023

    @akshay-joshi
    akshay-joshi
    on Aug 28, 2023
    Contributor
    More actions

    @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.

  17. firstDismay commented on Aug 28, 2023

    @firstDismay
    firstDismay
    on Aug 28, 2023
    Author
    More actions

    @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.

  18. adityatoshniwal
    added
    Bug
    on Dec 6, 2023
  19. dpage
    added 3 commits that reference this issue on Oct 15, 2026

    Fix Schema Diff treating functions that differ only in OUT arguments …

    2697a90

    Fix Schema Diff treating functions that differ only in OUT arguments …

    ff59f7f

    Fix Schema Diff treating functions that differ only in OUT arguments …

    09afc34
  20. dpage commented on Oct 15, 2026

    @dpage
    dpage
    on Oct 15, 2026
    Contributor
    More actions

    Fixed in 09afc34 (#10595).

  21. dpage
    closed this as completedon Oct 15, 2026
  22. github-project-automation
    moved this to Done in Ready for Sprint Bugson Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    • Ready for Sprint Bugs
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.