path counting on postgres