changed pg sql query