Hello,

I'm trying to write an application which will merge two or more databases
together.
The rules are that duplicate records will be added together.

As an example we can have two tables:

user(id integer primary, name text)

and

orders (id integer primary, apples integer, user_id foreign)

If you have two db's a and b they could look like:

a:
user(1, "bob")
user(2, "charlie")
orders(1, 4, 1)
orders(2, 2, 2)

b:
user(1, "bob")
user(2, "eve")
orders(1, 5, 1)
orders(2, 3, 2)

The resulting database c should then look like:

user(1, "bob")
user(2, "charlie")
user(3, "eve")

orders(1, 9, 1) <- 4 +5 apples got merged together for bob
orders(2, 2, 2) <- charlie remains the same
orders(3, 3, 3) <- eve got her foreign id changed because of the new layout
in user table

Currently I'm copying a to c
Then I read each record of b and match it with c.
To do this I find each id in users for the name present in a and find the
corresponding entry in table c.

If I have the apples = 5 user = "bob" isn't it possible to add the data
directly to c without performing a select?

Currently it's works but is painfully slow ... 500000 records can easily
take many hours.

Thanks in advance.

-- Henrik

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to