Always return correct primary key from postgres

The previous implementation failed when the primary key
had no sequence (eg UUID)

Used the code from rails 3.2