Re: [sqlite] Merging databases

2013-03-25 Thread Clemens Ladisch
Krzysztof wrote:
> I have daemon on server which each day create new sqlite database. Client
> application can download and present these databases. For example: User
> want to see data from last week so client application download 7
> files. Advantage of this defragmentation is that it don't need to download
> big files. Disadvantage is that create queries is tricky. So here is my
> question. Is SQLite has some function for merging data? I'm wondering about
> ATTACH DATABASE, but maybe there is a better way?

You can indeed use attached databases to merge data:

ATTACH DATABASE 'day42.sqlite' AS 'day42';
INSERT INTO MyTable SELECT * FROM day42.MyTable;

If the data does not have a timestamp, you'd have to add it:

INSERT INTO MyTable(name, value, whatever, day)
SELECT name, value, whatever, 42 FROM day42.MyTable;


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Merging databases

2013-03-25 Thread Krzysztof
Hi,

I have daemon on server which each day create new sqlite database. Client
application can download and present these databases. For example: User
want to see data from last week so client application download 7
files. Advantage of this defragmentation is that it don't need to download
big files. Disadvantage is that create queries is tricky. So here is my
question. Is SQLite has some function for merging data? I'm wondering about
ATTACH DATABASE, but maybe there is a better way?

Regards
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Merging databases

2005-05-07 Thread thatsanicehatyouhave
Hello,

Imagine you have a simple database with two tables, and a third to join them as 
a many-to-many relationship. Someone sends me an SQLite database as a file 
which has the same structure, but the data is different. I want to merge these 
two databases together keeping all of the relationships intact, without 
duplicating data.

For example, if the tables were "customers" and "products" and the one in 
between "orders", there is the possibility that some customers and/or products 
might be the same, but with different primary keys. The problem is that since 
the databases were independently created, a simple union will break the 
relationships since the primary keys will overlap.

I can think of brute force ways to do this, but I was wondering if anyone might 
have a good algorithm or technique to accomplish this efficiently.

Cheers!

Demitri