updates to query function in postgres