updated formula for postgreSQL