I’m using PostgreSQL 8.1, and I have two databases with one table names clients that are identical and contain +-50k rows each.
I need to obtain all ids in one table that aren’t in the other, I have the following solution
$sql = "SELECT id FROM clients WHERE id NOT IN(".pg_query($conn1,'SELECT id FROM clients').")";
$result = pg_query($conn2,$sql);
Before I run this, is this a good way to do it via PHP or are the other better faster ways?
Unfortunately I cant use dblink since I do not have privileges to install it.
If you can’t use a database link I think you will have to do it in the middleware – and this middleware should have a lot of RAM.
I would also recommend not to use PHP for this purpose, but if you have no other possibility, I would do it like this:
Best way would of course be, because ID is primary key, to write an own in_array-function which removes the ID from haystack when it’s found because it will not be searched for again and the next search loop will be a bit faster.