changed queries to work with postgresql.