Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Return an array into new table field

Help
Anonymous
2012-04-12
2012-09-19

  • Anonymous
    2012-04-12

    I am using MySQLdb with python. I need to do some calculation in python using
    variable values in an existing table, and then return the output back to the a
    MySQL table to continue data manipulation in MySQL. Say, the data table
    my_table contains fields A, B, C, x and y, I wrote a python function called
    fixit(lstX, lstY) calculate and returns a list of Z values. Ideally I would
    like to "paste" the values back to the my_table as an additional column, so to
    proceed with next step where x, y, z fields are needed.

    Right now I use cursor.executemany to insert Z into a new empty table, and
    since row number is not an default variable in MySQL (right?) I generate an
    auto increasing field (which serves as row number) in both the original
    my_table and the new table, and then join the two table using the auto
    increasing field. Is there an nicer way to do this? Thanks !

     
  • Cat slave
    Cat slave
    2012-04-12

    UPDATE my_table SET z=%s WHERE x=%s and y=%s

    with your execute_many.

     

  • Anonymous
    2012-04-12

    Thank you for the response. I thought about that at first, but concerned that
    using WHERE x=%s and y=%s will be slow when the table gets big.

     
  • Cat slave
    Cat slave
    2012-04-12

    add an index on the columns if necessary?