title: Mapping rows ids with external csv file?
body: <p>I have a csv file with addresses information: <code>zip</code>, <code>city</code>, <code>state</code>, <code>country</code>, <code>street</code>, <code>house_no</code> (the last one is house number). This is being Imported throught OpenERP import interface. So you can import related data by providing one of three - <code>name</code>, <code>database id</code> or <code>external id</code>. The simplest is by providing <code>name</code>. </p>
  
  <p>For example for city I don't need to specifically provide it's id (and change column from <code>street</code> to <code>street_id</code> and then that street id), but just its real name like <code>Some city</code>. If such city name exists in <code>city</code> table, then everything will be imported without problems. </p>
  
  <p>But problems arise when there are more than one city with same name. Then to solve name clashes I need to specifically provide those cities ids. But the problem is, there are so many addresses that is nearly impossible to just look and manually change names to ids. </p>
  
  <p>So I'm wondering if it's possible to write some script or pass that csv file to postgresql (or OpenERP using ORM) as condition so it would return me list of ids that matches conditions from csv file.</p>
  
  <p>In my database there is already imported all needed streets in <code>street</code> table and cities in <code>city</code> table.</p>
  
  <p><code>city</code> table has this structure (with example data):</p>
  
  <pre><code>id| name| state_id|
  1 | City1| 1
  2 | City1| 2
  3 | City2| 2|
  </code></pre>
  
  <p><code>state</code> table example:</p>
  
  <pre><code>id| name|
  1 | State1
  2 | State2
  </code></pre>
  
  <p>So as you can see same names can be distinguished by their id or by state_id or state name if you would go to <code>state</code> table.</p>
  
  <p>And an example of adddresses csv file (also in database there is table to import that information)</p>
  
  <pre><code>|zip| city | state_id| country | street| house_no
  123 | City1| 1       | Country1| Street1| 25a
  124 | City1| 2       | Country1| Street2| 34 
  125 | City2| 2       
  </code></pre>
  
  <p>If I validate such csv file through OpenERP interface, I get warning that there two cities with same name. And if I proceed, then it chooses city that was first imported in database and then some addresses will have city assigned for them with wrong state (keep in mind that column city is also used for various villages etc, so thats why there are same names in different states.</p>
  
  <p>So there I need to change from city names to there ids, but as I said there are hundreds of thousands of lines and doing manually is nearly impossible and would take lots of time.</p>
  
  <p>Finally what I need is to somehow pass all that information from addresses csv file into database, specifically into <code>city</code> table and get return of ids list. </p>
  
  <p>For example if I would input (as condition for <code>city</code> table):</p>
  
  <pre><code>name | state_id|
  City1| 1
  City1| 2
  City2| 2
  City1| 1
  </code></pre>
  
  <p>It should output to me this:</p>
  
  <pre><code>1
  2
  3
  1
  </code></pre>
  
  <p>Could someone suggest me how to get such result?</p>