MarkApplegate
asked on
Comparing two postgres tables and updating one with differences.
I have two tables in a postgres database
Table 1
newacctnumber
oldaccountnumber
date
Table 2
newacctnumber
oldaccountnumber
done
Table 2 contains all the newacctnumber/oldaccountnu mber entrees that exist in table 1. Some other steps are take and then the done is set to Y.
Table 1 is automatically generated each week, resulting in additional entreens being added.
What I need to do is update table 2 with new entrees that are in Table 1 but not already in Table 2.
This will be done thru an online page (administrators page) with php code. I have one method but it seems slow to me.
$query="Select * from table1";
$db = "poscoid";
$result = db_query($query, $db);
while ($r=pg_fetch_array($result ))
{
$newacctnumber = $r["newacctnumber"];
$oldacctnuber = $r["oldacctnumber"];
$query="Insert into table2(newacctnumber, oldacctnumber) values($newacctnumber,$old acctnumber ) where $newacctnumber not in (select newacctnumber from table2 where done = 'N')";
$db = "poscoid";
$updateresult = db_query($query, $db);
}
Table 1
newacctnumber
oldaccountnumber
date
Table 2
newacctnumber
oldaccountnumber
done
Table 2 contains all the newacctnumber/oldaccountnu
Table 1 is automatically generated each week, resulting in additional entreens being added.
What I need to do is update table 2 with new entrees that are in Table 1 but not already in Table 2.
This will be done thru an online page (administrators page) with php code. I have one method but it seems slow to me.
$query="Select * from table1";
$db = "poscoid";
$result = db_query($query, $db);
while ($r=pg_fetch_array($result
{
$newacctnumber = $r["newacctnumber"];
$oldacctnuber = $r["oldacctnumber"];
$query="Insert into table2(newacctnumber, oldacctnumber) values($newacctnumber,$old
$db = "poscoid";
$updateresult = db_query($query, $db);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER