Menu

Weird INSERT behaviour

Help
jcanto
2003-05-06
2012-09-19
  • jcanto

    jcanto - 2003-05-06

    Hello there.
    I've a problem with MySQLdb. I'm using version 0.9.2 (MySQL-python-0.9.2.win32-py2.2), with a 2.2.2 MySQL (for Windows).
    The insert is done in a quite simple table that looks like this:

    table datos (fecha timestamp(14), tipo varchar(255) not null, primary key(fecha,tipo))

    The insert itself is something like this:

    sql = "INSERT INTO datos (fecha,tipo) VALUES (%s,%s)"
    run_sql(sql,(fecha,'arranque'))

    Function "run_sql" basically connects to the db when the connection has not been done yet, and executes the query itself. The problem is that at first instance, the first insert works well, but when the program process others (while it is allready connected to the DB) it inserts well the data in the table, but raises a _mysql_exceptions.IntegrityError.

    I've traced the program again and again, but the execute of the query is done only once, so I don't understand why it raises such an error. Any help will be appreciated :) Thank you in advance.

     
    • Andy Dustman

      Andy Dustman - 2003-05-06

      Your primary key is (fecha,tipo). IntegrityError will be raised if you try to insert the same value twice (the primary key is required to be unique and not null). The only other possibility is that you using a transaction-safe table type (BDB or InnoDB) and there are two conflicting inserts.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.