[Tutor] Pouring a list into a dictionary then into database

Allen aschmidt at fredericksburg.com
Mon Sep 29 21:12:04 EDT 2003


REPLACE has the same syntax as INSERT. But, if it finds a duplicate 
based on a unique or primary key, it first deletes the row and then 
inserts the new row. Works great. No duplicate? Then it just does a 
normal insert.

I jumped the gun on my response because it was obvious where it would 
go...duh on my part.

But...what about for 'slightly' older versions... 2.1.3 to be specific?

Thanks

Allen


Danny Yoo wrote:

> 
> On Mon, 29 Sep 2003, Allen wrote:
> 
> 
>>>you can also call the executemany() method to do this operation on your
>>>whole list of key/value pairs.  So you should be able to say:
>>>
>>>###
>>>sql = "replace into tablename %s values (%s)"
>>>crsr.executemany(zip(headings, foundData))
>>>###
>>
>>So where does the sql go??
> 
> 
> Hi Allen,
> 
> 
> ... Doh.  Good question.  My bad.
> 
> 
> I should have written:
> 
> ###
> sql = "replace into tablename %s values (%s)"
> crsr.executemany(sql, zip(headings, foundData))
> ###
> 
> instead.  My apologies!
> 
> 
> I do have a good defense though: ignorance!  *grin* The reason I couldn't
> test this code is because I'm not familiar at all with REPLACE and wasn't
> able to run it on a test database.  I'm only familiar with INSERT, UPDATE,
> DELETE, and SELECT.  Is REPLACE part of the SQL standard?
> 
> 
> Talk to you later!
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 




More information about the Tutor mailing list