title: export very large sql file into csv with Python or R
body: <p>I have a large sql file (20 GB) that I would like to convert into csv. I plan to load the file into Stata for analysis. I have enough ram to load the entire file (my computer has 32GB in RAM)</p>
  
  <p>Problem is: the solutions I found online with Python so far (sqlite3) seem to require more RAM than my current system has to:</p>
  
  <ul>
  <li>read the SQL</li>
  <li>write the csv</li>
  </ul>
  
  <p>Here is the code</p>
  
  <pre><code>import sqlite3
  import pandas as pd
  
  con=sqlite3.connect('mydata.sql')
  query='select * from mydata'
  data=pd.read_sql(query,con)
  data.to_csv('export.csv')
  con.close()
  </code></pre>
  
  <p>The sql file contains about 15 variables that can be timestamps, strings or numerical values. Nothing really fancy.</p>
  
  <p>I think one possible solution could be to read the sql and write the csv file one line at a time. However, I have no idea how to do that (either in R or in Python)</p>
  
  <p>Any help really appreciated!</p>