Skip to content

fix(postgresql): parsing bug with expression based unique indexes on postgres - #5726

Merged
jacek-prisma merged 4 commits into
prisma:mainfrom
luis-dfns:main
Feb 6, 2026
Merged

fix(postgresql): parsing bug with expression based unique indexes on postgres#5726
jacek-prisma merged 4 commits into
prisma:mainfrom
luis-dfns:main

Conversation

@luis-dfns

@luis-dfns luis-dfns commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

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"]

Copilot AI review requested due to automatic review settings January 13, 2026 13:19
@luis-dfns luis-dfns changed the title Fix parsing bug with expression based unique indexes on postgres fix(postgresql): parsing bug with expression based unique indexes on postgres Jan 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of split(" (") 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.

Comment thread quaint/src/tests/query/error.rs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CLAassistant

CLAassistant commented Jan 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed-hq

codspeed-hq Bot commented Jan 13, 2026

Copy link
Copy Markdown

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing luis-dfns:main (0559d36) with main (7f62a0e)

Summary

✅ 11 untouched benchmarks
⏩ 11 skipped benchmarks1

Footnotes

  1. 11 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jacek-prisma

Copy link
Copy Markdown
Contributor

Hi @luis-dfns!
Thanks for the contribution.
Looks like the newly added test is failing in CI.

@luis-dfns

Copy link
Copy Markdown
Contributor Author

hi @jacek-prisma ! I had some trouble executing the tests locally, but it should work now

@jacek-prisma
jacek-prisma merged commit 88064eb into prisma:main Feb 6, 2026
96 of 97 checks passed
dimsssss pushed a commit to dimsssss/prisma-engines that referenced this pull request Feb 26, 2026
…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>
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.

4 participants