Skip to content

Conversation

adsa95
Copy link
Contributor

@adsa95 adsa95 commented Aug 20, 2025

This PR fixes a bug in the psql driver where partial unique indexes will mark a column as unique, which is not true as it is only unique over a subset of rows. This currently leads to bugs such as #1436 where incorrect relations are generated (one-to-one instead of one-to-many) but could potentially also lead to other bugs where this difference is important.

This fix is implemented by adding a condition to the query in *PostgresDriver.loadUniqueColumns that excludes partial indexes by filtering on the pg_index.indpred column which will be null if it is not a partial index as stated in the PostgreSQL docs:

indpred pg_node_tree
Expression tree (in nodeToString() representation) for partial index predicate. Null if not a partial index.

@stephenafamo
Copy link
Collaborator

Add a note in CHANGELOG.md 🙏🏾

@adsa95
Copy link
Contributor Author

adsa95 commented Aug 26, 2025

@stephenafamo done! Also reverted some accidental autoformatting that was not meant to be included.

@stephenafamo stephenafamo merged commit b385498 into aarondl:master Aug 26, 2025
2 checks passed
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.

2 participants