converted sql script from mysql to postgres