postgresql: Add type annotation for 'db' argument
This allows mypy to actually type-check calls to db methods.
This commit also fixes an issue found by mypy.
Thanks to @anlambert noticing this issue in !696 (closed)
Migrated from D5937 (view on Phabricator)