trying again to make SQL compatible with postgresql