fix(postgresql): parsing bug with expression based unique indexes on postgres - #5726
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in parsing unique constraint violation errors for PostgreSQL when the constraint involves expression-based indexes. The issue occurs when parsing the error detail message to extract field names from expressions like json_data->>'field'.
Changes:
- Modified the parsing logic to use
splitn(2, " (")instead ofsplit(" (")to correctly handle expressions containing parentheses - Added test coverage for expression-based unique indexes on PostgreSQL
- Changed quote character from escaped to raw string format for improved readability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| quaint/src/connector/postgres/error.rs | Fixed parsing logic to handle expression-based unique indexes by using splitn(2) and simplified quote escaping |
| quaint/src/tests/query/error.rs | Added comprehensive test case for expression-based unique indexes with JSONB field extraction |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
|
Hi @luis-dfns! |
|
hi @jacek-prisma ! I had some trouble executing the tests locally, but it should work now |
…postgres (prisma#5726) Fixes a bug where the unique key violation parsing incorrectly returns extra "comma" characters for expression based unique indexes such as: ``` CREATE UNIQUE INDEX "unique_idx" ON "table_name"( "column_1", (column_2->>'field'), ); ``` In which case the columns affected would previously be returned as `["column_1,"]` instead of `["column_1"]` --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: jacek-prisma <malec@prisma.io>
Fixes a bug where the unique key violation parsing incorrectly returns extra "comma" characters for expression based unique indexes such as:
In which case the columns affected would previously be returned as
["column_1,"]instead of["column_1"]