Tuukka Norri committed 015ecef

Fixed a bug which caused PGTSTableDescription to return the wrong index as the primary key under certain conditions
- The indices were sorted by the index oid instead of the relation oid and primarity.
- Added an additional check for this.

Comments (0)

Files changed (2)


 	@" WHERE i.indisunique = true AND "
 	@"  n.nspname NOT IN ('information_schema', 'baseten') AND "
 	@"  n.nspname NOT LIKE 'pg_%' "
-	@" ORDER BY i.indexrelid ASC, i.indisprimary DESC";
+	@" ORDER BY i.indrelid ASC, i.indisprimary DESC";
 	PGTSResultSet* res = [connection executeQuery: query];
 	ExpectV ([res querySucceeded]);


 #import "PGTSTableDescription.h"
 #import "PGTSColumnDescription.h"
+#import "PGTSIndexDescription.h"
 #import "PGTSCollections.h"
 #import "PGTSScannedMemoryAllocator.h"
 #import "BXLogger.h"
 	Expect (mUniqueIndexes);
 	id retval = nil;
 	IdList::const_iterator it = mUniqueIndexes->begin ();
-	if (mUniqueIndexes->end () != it)
+	if (mUniqueIndexes->end () != it && [*it isPrimaryKey])
 		retval = *it;
 	return retval;