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

From Rodrigo De León
Subject Re: What is the best way to merge two disjoint tables?
Date
Msg-id a55915760709071032o3387295cma2bdde5a8ede60f8@mail.gmail.com
Whole thread Raw
In response to What is the best way to merge two disjoint tables?  (Chansup Byun <Chansup.Byun@sun.com>)
Responses Re: What is the best way to merge two disjoint tables?  (Chansup Byun <Chansup.Byun@Sun.COM>)
List pgsql-general
On 9/7/07, Chansup Byun <Chansup.Byun@sun.com> wrote:
> Can someone show me an example SQL statement?

I suppose you could add a constant, non-overlapping number to add to
the duplicate IDs, say 1000, and then this:

SELECT COALESCE(T1.U_USER, T2.U_USER) AS U_USER
     , COALESCE(CASE
                  WHEN EXISTS(SELECT 1
                                FROM TABLEB
                               WHERE U_ID = T1.U_ID
                                 AND U_USER <> T1.U_USER)
                    THEN T1.U_ID + 1000
                  ELSE T1.U_ID
                END
              , T2.U_ID
               ) AS U_ID
  FROM TABLEA T1 FULL JOIN TABLEB T2 ON T1.U_USER = T2.U_USER

will generate a new list of U_USERs and U_IDs.

Good luck.

pgsql-general by date:

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