made sql compatible with pg