Re: Dump in-memory database to disk?

Gerhard Häring <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thomas Weholt wrote:
> Thanks for your reply :-)
> 
> I was hoping to avoid all the inserts and use some way of writing all
> the data directly to a database-file. I believe that would be faster,
> but perhaps it's not possible so I'll have to use the method you
> described.

I'm pretty sure the way I described is the only reasonable one. CREATE
TABLE AS SELECT is also as fast as you can normally get with a relational
database, aside from perhaps native dump/load calls, which SQLite does not
have.

> On a side note; are there any speed enhancements gained by using
> executemany vs. just execute?

There's only a single CREATE TABLE AS SELECT per table, and you can't use
executemany to replace the loop around that. executemany can only be used
for parametrized SQL statements. And you can only parametrize (with ?)
*values* in SQL, not *identifiers* like table or column names.

As a side-note, pysqlite 2.1.0 and later caches compiled statements anyway,
so execute() with parametrized statements is almost as fast as
executemany() nowadays.

- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFFmHadIO4ozGCH14RAgW6AJ9CnlVU/plz+eFOQx0E6iVW1KJFNwCgrBuz
mynbswjCjr4wDrFaHyE7s4w=
=rOMR
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.