Changed query for postgres