What is the best way to merge two disjoint tables? - Mailing list pgsql-general

From Chansup Byun
Subject What is the best way to merge two disjoint tables?
Date
Msg-id 46E176B3.7040802@sun.com
Whole thread Raw
Responses Re: What is the best way to merge two disjoint tables?
List pgsql-general
Hi Gurus,

I have two disjoint tables, for examples, of user lists.

Some users appear both tables. They may or may not have the same u_id.
Some users only appear one table.

I would like to merge tableB into tableA with the condition that each
user has a unique id.
Also I would like to keep u_id in the tableB. This requires to modify
u_id of tableA if there are matching users but different u_id.
Also those users only in tableA should change their u_id, if needed, to
avoid any conflict with u_id from tableB.

Can someone show me an example SQL statement?

tableA:
  u_user  | u_id
----------+------
 user1   |   46
 user2   |   30
 user4   |   22
 user5   |   48
 user7   |    6
user9    |    1
user11  |   45
user12  |   33

tableB:
  u_user  | u_id
----------+------
user1    |   46
user2    |   30
user3   |   22
user6   |   48
user8   |    6
user10  |    1

Thanks,

- Chansup


pgsql-general by date:

Previous
From: Scott Ribe
Date:
Subject: Re: an other provokative question??
Next
From: Markus Schiltknecht
Date:
Subject: Re: Connection Pooling directly on Postgres Server