fix query to work with PG