I have databases which manage files. The reason that there are multiple is that they live on separate drives (think USB drives). I want to write queries which apply to files on all drives. The problem is that I cannot take down the view to recreate it with another database (its being used). Therefore, I was wondering if there is a way to write a view to union all tables with the same name in each of the databases from .databases? That way, when a new database is attached, i dont have to take down the view.
Maybe as the closest answer, would it be possible to write a trigger on ATTACH and have the trigger recreate the view (in order to at least minimize downtime)?
SQLite doesn’t support any kind of ‘attach’ trigger that I’m aware of, only delete, insert, and update.
What you want to do is probably best done by your program, not inside SQLite itself. You should be able to manually drop and re-create the view (necessary since views can’t be modified) in your own code anytime you do an attach. Of course this would require a lock (making the table unusable as you said), but that would probably be necessary even if SQLite was doing the work for you.
Either way, the view creation is extremely fast, so it shouldn’t affect your program’s performance.