Title: Column names in ON CONFLICT DO UPDATE SET clause not validated · Issue #4291 · sqlc-dev/sqlc · GitHub
Open Graph Title: Column names in ON CONFLICT DO UPDATE SET clause not validated · Issue #4291 · sqlc-dev/sqlc
X Title: Column names in ON CONFLICT DO UPDATE SET clause not validated · Issue #4291 · sqlc-dev/sqlc
Description: Version 1.30.0 What happened? Bug: sqlc does not validate column names in ON CONFLICT DO UPDATE SET clause Description sqlc fails to validate column names in ON CONFLICT ... DO UPDATE SET clauses against the table schema. This allows inv...
Open Graph Description: Version 1.30.0 What happened? Bug: sqlc does not validate column names in ON CONFLICT DO UPDATE SET clause Description sqlc fails to validate column names in ON CONFLICT ... DO UPDATE SET clauses a...
X Description: Version 1.30.0 What happened? Bug: sqlc does not validate column names in ON CONFLICT DO UPDATE SET clause Description sqlc fails to validate column names in ON CONFLICT ... DO UPDATE SET clauses a...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/4291
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Column names in ON CONFLICT DO UPDATE SET clause not validated","articleBody":"### Version\n\n1.30.0\n\n### What happened?\n\n # Bug: sqlc does not validate column names in ON CONFLICT DO UPDATE SET clause\n\n ## Description\n\n sqlc fails to validate column names in `ON CONFLICT ... DO UPDATE SET` clauses against the table schema. This allows invalid queries to be generated that will only fail at runtime when executed against the database.\n\n ## Steps to Reproduce\n\n 1. Create a schema file (`migrations/schema.sql`):\n ```sql\n CREATE TABLE IF NOT EXISTS cart_items\n (\n owner_id VARCHAR(255) NOT NULL,\n product_id UUID NOT NULL,\n price_amount DECIMAL NOT NULL,\n price_currency VARCHAR(3) NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,\n PRIMARY KEY (owner_id, product_id)\n );\n\n CREATE INDEX idx_cart_items_owner ON cart_items (owner_id);\n\n 2. Create a query file (query.sql) with an invalid column name in the SET clause:\n -- name: AddItem :exec\n INSERT INTO cart_items (owner_id, product_id, price_amount, price_currency)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (owner_id, product_id) DO UPDATE\n SET price_amount1 = EXCLUDED.price_amount1, price_currency = EXCLUDED.price_currency;\n\n Note: The column is price_amount (exists), but the query references price_amount1 (does not exist)\n\n 3. Create sqlc.yaml:\n version: \"2\"\n sql:\n - engine: \"postgresql\"\n schema: \"migrations/schema.sql\"\n queries: \"query.sql\"\n gen:\n go:\n package: \"querytest\"\n out: \"generated\"\n\n 4. Run sqlc generate\n\n Expected Behavior\n\n sqlc should report an error similar to:\n query.sql:5:15: column \"price_amount1\" of relation \"cart_items\" does not exist\n\n This matches the behavior when running the same query through PostgreSQL directly.\n\n Actual Behavior\n\n sqlc generates code successfully without any errors, embedding the invalid SQL:\n const addItem = `... SET price_amount1 = EXCLUDED.price_amount1 ...`\n\n The generated Go code compiles successfully, but the query will fail at runtime with a database error.\n\n Root Cause\n\n sqlc does not validate column names in ON CONFLICT ... DO UPDATE SET clauses against the table schema. The validation code path is missing:\n\n - OnConflictClause is parsed correctly by the PostgreSQL engine\n - But it's never validated in the compiler phase\n - Column validation happens in internal/compiler/output_columns.go for SELECT/WHERE clauses, but not for ON CONFLICT clauses\n - The validate.InsertStmt() function in internal/sql/validate/insert_stmt.go only validates column count vs value count, not SET clause columns\n\n Files Affected\n\n - internal/compiler/analyze.go - No validation for ON CONFLICT\n - internal/sql/validate/insert_stmt.go - Missing ON CONFLICT SET column validation\n - internal/compiler/output_columns.go - Missing ON CONFLICT SET clause handling\n\n Workaround\n\n Until this is fixed, ensure column names in ON CONFLICT DO UPDATE SET clauses are manually verified against the schema.\n\n Environment\n\n - sqlc version: v1.30.0 (confirmed on latest main)\n - Database engine: PostgreSQL\n - Go version: 1.25.0+\n\n### Relevant log output\n\n```shell\n\n```\n\n### Database schema\n\n```sql\n\n```\n\n### SQL queries\n\n```sql\n\n```\n\n### Configuration\n\n```yaml\n\n```\n\n### Playground URL\n\n_No response_\n\n### What operating system are you using?\n\nmacOS\n\n### What database engines are you using?\n\nPostgreSQL\n\n### What type of code are you generating?\n\nGo","author":{"url":"https://github.com/nikolayk812","@type":"Person","name":"nikolayk812"},"datePublished":"2026-02-08T15:41:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/4291/sqlc/issues/4291"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:755f45ae-f0e1-bf02-23cf-9f5a96930ba7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 92E6:2144F:978AEC:D7C4F0:6A5109F5 |
| html-safe-nonce | a141e5a6006f7ee63b4a1afe32f6be1d4509ae0077b96fcadd4728123e3da21f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkU2OjIxNDRGOjk3OEFFQzpEN0M0RjA6NkE1MTA5RjUiLCJ2aXNpdG9yX2lkIjoiMTYxMTYzNTUyODQxMDY2MzQxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e02b687a1f30362d8b7b275263028f0e82e8fe6d58d0f74dc29151472d419595 |
| hovercard-subject-tag | issue:3912965347 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc/4291/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4474d0b8ac9e08b503acf53e05173a0746b95927ed599e45417a3a1ac4a78ee7/sqlc-dev/sqlc/issues/4291 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4474d0b8ac9e08b503acf53e05173a0746b95927ed599e45417a3a1ac4a78ee7/sqlc-dev/sqlc/issues/4291 |
| og:image:alt | Version 1.30.0 What happened? Bug: sqlc does not validate column names in ON CONFLICT DO UPDATE SET clause Description sqlc fails to validate column names in ON CONFLICT ... DO UPDATE SET clauses a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nikolayk812 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b076e100febaa00374cd89239f915d00dd3187f7c68b12bc2b7688181305344d |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 193160679 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193160679 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d129404fc45ea64edb1b98567c53e55b395536f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width