[Tutor] Is it possible to archive subsets of data from an SQLite db and restore it later?

Ben Finney ben+python at benfinney.id.au
Tue Aug 18 05:54:47 CEST 2015

boB Stepp <robertvstepp at gmail.com> writes:

> My wife had an interesting request tonight: Would it be possible to
> have two dbs, one that is the current working db, and the other an
> archival db for students who have left the school?

(Note that this isn't anything to do with Python per se, and would be
better discussed on an SQLite-specific forum.)

A relational database (such as implemented by SQLite) is designed to
contain all the relevant truths, and is not designed to have truths
split across different databases.

So you will be better served by *adding* the distinction (“date when
this student left the school”) to the database, and use that distinction
in queries.

To make your job easier, you can store the distinguishing field and
prepare “views” which show only subsets (“students who have left the
school”, “students who have not left the school”, “all students”)
<URL: https://www.sqlite.org/lang_createview.html> against which you can
perform further queries.

> I realized that the method I was going to write a test for would not
> be an easy thing to do. Which made me realize that the method I was
> hoping to start coding tonight was ill-conceived! ARGH! To bed I now
> go ... Is TDD the programmer's version of writer's block? ~(:>)

No, it's the programmer's equivalent of saving time by having that
realisation come *before* committing wasted time on a poor design :-)

 \      “If you don't fail at least 90 percent of the time, you're not |
  `\                                    aiming high enough.” —Alan Kay |
_o__)                                                                  |
Ben Finney

More information about the Tutor mailing list