Comparing two rows in PostgreSQL I have an employee table in two different servers with the same structure. I want to shift all the data to main server but there are some records already exists in main server that are duplicate of local one's but are incomplete, now i want to compare these records so i can chose the most completed one and delete the incomplete one from one of the servers. surely i will use dblink to compare but what would be the SQL query for it?

in short some of the records are incomplete in local server while some of them are incomplete in main. is there any way to compare them and chose the completest one?

Thank you in advance.
instead of dblink, I recommend you to use potgres_fdw.
When you map the foreign table, you can use a simple SELECT INSERT to solve your problem. E.g.:
INSERT INTO remote.employee
SELECT local.* FROM public.employee AS local
WHERE NOT EXISTS ( 
     SELECT 1 FROM remote.employe AS remote
     WHERE local.id = remote.id
)


Remember to fix the WHERE filter to fit your table's primary keys.

EDIT: I make a small sample how to compare the rows of both tables as a gist: https://gist.github.com/sebastianwebber/7b4ab352733e8aab8b03f94d8aa0c7a9

The easy way to compare the rows is:
SELECT
    e1.id as e1_pk,
    e2.id as e2_pk,
    COALESCE(e1.* = e2.*, false) as equal
FROM employee1 as e1
RIGHT JOIN employee2 as e2 USING (id);


Hope it helps.