pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Overloaded Functions Not Fully Dumped

Open lionas32 opened this issue 1 year ago • 0 comments

Problem

When dumping a PostgreSQL schema with overloaded functions (same name, different signatures), pgschema dump only exports one overload, missing the others.

Example

-- Database has TWO overloads:
CREATE FUNCTION calculate_price(base_price numeric) RETURNS numeric ...
CREATE FUNCTION calculate_price(base_price numeric, discount_percent numeric) RETURNS numeric ...

pgschema dump only outputs the last processed function. This is true for both multi-file and single-file outputs.

Internally, functions look to be stored by name only, so overloads overwrite each other.

As a fix tested out including argument types in the function key in buildFunction in ir/inspector.go (big shoutout to Claude Code):

func (i *Inspector) buildFunctions(ctx context.Context, schema *IR, targetSchema string) error {
                ...
-               dbSchema.SetFunction(functionName, function)
+               functionKey := functionName + "(" + function.GetArguments() + ")"
+               dbSchema.SetFunction(functionKey, function)

This produces a dump with all function overloads.

lionas32 avatar Dec 04 '25 09:12 lionas32