get postgres queries working with 'where' clause (or no where clause)