yes, this could get called on quite large tables (maybe not billions ...). The second solution looks useful - I'll try it on some test data. thanks both of you. ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster