Fixed error in sql request not working with postgres