Fix query for pg