fix: normalize function argument types to prevent spurious replacements#158
Closed
p-c-h-b wants to merge 1 commit intopgplex:mainfrom
Closed
fix: normalize function argument types to prevent spurious replacements#158p-c-h-b wants to merge 1 commit intopgplex:mainfrom
p-c-h-b wants to merge 1 commit intopgplex:mainfrom
Conversation
This fixes a bug where function replacements would fail because PostgreSQL stores parameter types with schema qualifications (e.g., 'public.user_status') while the source SQL might use unqualified names (e.g., 'user_status'). When comparing function signatures, pgschema would treat these as different functions and try to DROP the old one before CREATE OR REPLACE, causing failures when other objects referenced the function. Changes: - Added stripSchemaPrefixFromType() helper to normalize type names in function arguments by removing schema prefixes that match the function's schema - Modified Function.GetArguments() to strip schema prefixes from all parameter types before building the argument signature - This ensures 'public.user_status' and 'user_status' are treated as identical when comparing function signatures Fixes pgplex#155 (partially - this is the third of three fixes)
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds schema prefix normalization for function parameter types to ensure stable function identification across PostgreSQL schema-qualified type names. The main purpose is to strip matching schema prefixes from parameter types when building function argument strings.
- Added
stripSchemaPrefixFromTypehelper function to normalize schema-qualified type names - Modified
GetArgumentsmethod to use the new normalization function - Applied consistent formatting to struct field alignments and removed extraneous blank lines
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a bug where function signature comparison would incorrectly treat functions as different when PostgreSQL stores parameter types with schema qualifications while the source SQL uses unqualified names.
Problem
When PostgreSQL stores a function, it may qualify custom type names with their schema (e.g.,
public.user_status). However, source SQL often uses unqualified type names (e.g.,user_status).When pgschema compares the old and new function signatures:
my_func(public.user_status)my_func(user_status)pgschema would treat these as different functions and attempt to:
The DROP would fail if other objects (views, triggers, other functions) referenced
my_func, even thoughCREATE OR REPLACEwould have worked fine.Solution
Added signature normalization in
ir/ir.go:New helper function
stripSchemaPrefixFromType(typeName, schema)that removes schema prefixes from type names when they match the function's own schema:"public".user_status→user_statuspublic.user_status→user_statusother_schema.type→other_schema.typeModified
Function.GetArguments()to normalize all parameter types before building the signature string used for comparison.This ensures that
public.user_statusanduser_statusare treated as identical when comparing function signatures, allowingCREATE OR REPLACEto work instead of attempting a DROP.Changes
stripSchemaPrefixFromType()helper functionFunction.GetArguments()to apply normalization to all parameter typesFixes #155 (partially - this is the third of three fixes mentioned in the issue)