second attempt to make query work with pg