check_pgsql: Introduced support for querying data.

These commits add support for checking thresholds against values queried from a PostgreSQL database along with a couple of related fixes/enhancements.