title: How can I attach an in-memory SQLite database in Python?
body: <p>I'd like to merge SQLite databases, and some may be in memory. I create the in-memory databases by specifying the database path as <code>:memory:</code>. Following <a href="https://stackoverflow.com/a/11089277">this post</a>, using the <code>attach</code> feature of SQLite seems like both a simple and efficient approach. But how can I specify my in-memory database as the source to attach?</p>
  
  <p>For example, I'd want to do something like:</p>
  
  <pre><code>c1 = sqlite3.connect(":memory:")
  c1.execute(...create table, insert a bunch, commit...)
  
  c2 = sqlite3.connect(":memory:")
  c2.execute("""
    ATTACH ? AS ToMerge;
    BEGIN; 
      INSERT INTO Records SELECT * FROM ToMerge.Records; 
    COMMIT;
  """, (c1.get_attach_id(), ))
  </code></pre>
  
  <p>but, of course, <code>c1.get_attach_id()</code> is a method I made up for demonstration purposes, since using the string <code>:memory:</code> would be ambiguous. How can I specify the existing <code>c1</code> database?</p>