I don't think your algorithm for calculating the number of days in the overlap will work. Picture a scenario where we have one date range that covers 100 days, and another that covers 10 days, and they overlap by 2 days. Doing "age(<first range>) - age(<second range>)" will return 90 days, not 2 days. ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match