fix: validate column names in ON CONFLICT DO UPDATE SET clause#4306
Closed
rubensantoniorosa2704 wants to merge 2 commits intosqlc-dev:mainfrom
Closed
fix: validate column names in ON CONFLICT DO UPDATE SET clause#4306rubensantoniorosa2704 wants to merge 2 commits intosqlc-dev:mainfrom
rubensantoniorosa2704 wants to merge 2 commits intosqlc-dev:mainfrom
Conversation
- Add OnConflictClause validation in internal/sql/validate/on_conflict.go - Integrate validation into analyze.go pipeline - Add unit tests (5 cases) - Add endtoend testcase for invalid column TODO: - Test qualified column names (cart_items.col) - Test composite expressions on right side of SET - Test WHERE clause in ON CONFLICT - Test explicit schema (public.cart_items)
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.
I started working on this issue that's been open for a couple of weeks.
I've implemented the core validation logic in
internal/sql/validate/on_conflict.gowith helper functions to validate both the SET target columns and EXCLUDED references against the table schema.The implementation returns PostgreSQL error code 42703 (undefined_column) when columns don't exist, which matches what PostgreSQL itself would do.
I know the test coverage isn't complete yet, and that's where I could use some help.
Right now I have the basic happy path tests (valid columns, invalid columns, DO NOTHING), but there are edge cases I want to make sure we cover properly - like case-insensitive matching, quoted identifiers, complex expressions with multiple EXCLUDED references, and making sure error messages and locations are accurate.
I'm submitting this as a draft so the team can take a look at the approach and let me know if there's anything I'm missing or if the direction is right.
Any feedback on what additional test cases would be important would be really helpful.
Note: This implementation was developed with AI assistance. While the core logic appears sound and tests pass, I'd appreciate extra scrutiny on the approach and edge cases. I'm still getting familiar with the codebase patterns, so I'm open to detailed feedback and pair reviews if needed to improve this further.
Closes #4291