On 13 Aug 2015 at 11:34, Chris Parsonson <z2668856 at gmail.com> wrote:

> Has anybody ever used this ATTTACH command?

Here's what I do to move a row from one database to another (same table/column 
defs). I have to go via a temporary db (I use the :memory: one) since the 
primary key needs a new value in the second db. The original row in question 
has for example a value of 27 for its primary key (absid) in the following:

  <connect to first database>
  attach database ':memory:' as mem;
  create table mem.messages as select * from main.messages where absid=27;
  update mem.messages set absid=null;
  attach database '/path/to/second/db' as dst;
  insert into dst.messages select * from mem.messages;
  delete from main.messages where absid=27;
  <close database connection>

I developed this approach (for my use case) using the sqlite3 CLI program to 
ensure the general approach worked before trying it with my programming 
language (PHP). You might benefit from doing the same.

--
Cheers  --  Tim

Reply via email to