I know this list is not suppose to be used for general support questions, but I am having a hard time trying to figure out how to use executemany with a list of dictionaries as the second parameter. I will greatly appreciate any help that can be offered.

In my code, I have created some dictionaries:
    d1 = {"name": "name1", "value": "value1"}
    d2 = {"name": "name2", "value": "value2"}
    d3 = {"name": "name3", "value": "value3"}
    d4 = {"name": "name4", "value": "value4"}

And then I call enterResourceAVs with this call:
    testStore.enterResourceAVs(p2, [d1,d2,d3,d4])


the following exception error is raised:
    self.cursor.executemany(query, AVs)
File "/u/knappr/perftrak/database/PSU_PSQL/PyGreSQL-3.6.2/pgdb.py", line 185, in executemany
    raise DatabaseError, "error '%s' in '%s'" % ( msg, sql )
pg.DatabaseError: error 'ERROR:  syntax error at or near ":" at character 84
' in 'insert into resource_attribute (resource_id, name, value, attr_type) values (5157, :name, :value, 'string')'


enterResourceAVs() is defined as this:
def enterResourceAVs(self, id, AVs):
    """Takes an entry identifier, a list of dictionaries of
    (name,value). It enters the AVs list into resource attribute
    with idName = id. Currently enters all attr_type fields as
    "string"
     Returns: nothing
    """

    try:
        if len(AVs) > 0:
            query = "insert into resource_attribute " +\
                    "(resource_id, name, value, attr_type) "
            query += "values (%d, :name, :value, 'string')" % id
            self.cursor.executemany(query, AVs)
    except:
        raise


Thank you,
Rashawn Knapp


_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to