Fix SQLPrimaryKeys to exclude INCLUDE columns from results#171
Merged
davecramer merged 5 commits intopostgresql-interfaces:mainfrom Apr 14, 2026
Merged
Fix SQLPrimaryKeys to exclude INCLUDE columns from results#171davecramer merged 5 commits intopostgresql-interfaces:mainfrom
davecramer merged 5 commits intopostgresql-interfaces:mainfrom
Conversation
When a PRIMARY KEY is created with an INCLUDE clause (PostgreSQL 11+), SQLPrimaryKeys incorrectly returned both the key columns and the included columns. For example, given PRIMARY KEY (a, b) INCLUDE (c, d), all four columns were returned instead of just a and b. The root cause was that the pg_attribute join on the index relation iterated over all index attributes without distinguishing key columns from included columns. Fix by adding a filter on i.indnkeyatts when connected to PostgreSQL >= 11, which limits results to only the actual key attributes. Both query paths in PGAPI_PrimaryKeys are fixed. Add a regression test that creates a table with a composite primary key using INCLUDE and verifies only the key columns are returned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a PRIMARY KEY is created with an INCLUDE clause (PostgreSQL 11+),
SQLPrimaryKeys incorrectly returned both the key columns and the
included columns. For example, given PRIMARY KEY (a, b) INCLUDE (c, d),
all four columns were returned instead of just a and b.
The root cause was that the pg_attribute join on the index relation
iterated over all index attributes without distinguishing key columns
from included columns. Fix by adding a filter on i.indnkeyatts when
connected to PostgreSQL >= 11, which limits results to only the actual
key attributes. Both query paths in PGAPI_PrimaryKeys are fixed.
Add a regression test that creates a table with a composite primary key
using INCLUDE and verifies only the key columns are returned.
fixes #170