[sqlalchemy] translating many-to-many relationship from CSV to database?

2014-10-13 Thread James Hartley
I have a CSV file with lots of redundant data which models many-to-many
relationships.  I'm needing to scrub the data as it is inserted into the
database littered with unique constraints.  Is there a way to insert the
data once without querying for each object before inserting?

I'm sure this is a common CSV translation nit, but it is new to me.

Thanks for any insight provided!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] translating many-to-many relationship from CSV to database?

2014-10-13 Thread Michael Bayer
typically I load all the records I'm going to be working with at once, and 
assemble them into dictionaries or other data structures so that as I process 
the csv data, I can look things up in the local dictionary for the modify.

if the data you get from your CSV can all relate to the primary key of the 
objects, then you can use session.merge(), applying the existing primary key to 
a new object, which will be merged into the state of the existing row.   This 
also emits a SELECT for those rows, but again if you load them up ahead of 
time, the check is against the local identity map.


On Oct 13, 2014, at 2:22 AM, James Hartley jjhart...@gmail.com wrote:

 I have a CSV file with lots of redundant data which models many-to-many 
 relationships.  I'm needing to scrub the data as it is inserted into the 
 database littered with unique constraints.  Is there a way to insert the data 
 once without querying for each object before inserting?
 
 I'm sure this is a common CSV translation nit, but it is new to me.
 
 Thanks for any insight provided!
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.