Skip to content

Comments

fix: validate column names in ON CONFLICT DO UPDATE SET clause#4306

Closed
rubensantoniorosa2704 wants to merge 2 commits intosqlc-dev:mainfrom
rubensantoniorosa2704:fix/on-conflict-column-validation
Closed

fix: validate column names in ON CONFLICT DO UPDATE SET clause#4306
rubensantoniorosa2704 wants to merge 2 commits intosqlc-dev:mainfrom
rubensantoniorosa2704:fix/on-conflict-column-validation

Conversation

@rubensantoniorosa2704
Copy link
Contributor

@rubensantoniorosa2704 rubensantoniorosa2704 commented Feb 21, 2026

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.go with 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

- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Column names in ON CONFLICT DO UPDATE SET clause not validated

1 participant