def attr_sum_of_nodes(con,attr_name,node_ids=None):
    """Get the SUM() of node_ids's values for attr_name.
    
    con: a SQLite connection
    attr_name: The name of the attr values to fetch.
    node_ids: a list of ids to sompute the sum from.
    Returns a number that is the requested sum.
    """
    if node_ids is None:
        sql = "select sum(value) from attrs where name = '%s' group by name" % attr_name
    else:
        ids = (str(id) for id in node_ids)
        sql = "select sum(value) from attrs where name = '%s' and parent in (%s) group by name" % (attr_name, ','.join(ids))
    cur = con.execute(sql)
    row = cur.fetchone()
    if row:
        return row[0]
    else:
        return 0