Amalgamation of Postgres querys and MySQL.

The codebase is really messy, next commit will consolidate everything.