changed sql to pg