Lists: | pgsql-general |
---|
From: | o(dot)blomqvist(at)secomintl(dot)com (Otto Blomqvist) |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Copy data from one table to another, where some records might already be present |
Date: | 2004-08-10 15:27:32 |
Message-ID: | c501cb7d.0408100727.70b85c7e@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hello !
I have two tables with identical schema. I want to copy all data from
Table A to Table B, but table B might already have some of table A:s
data (each record is identified using record_numbers). I would suspect
this can be accomlished using a 2 stage query, first performing a join
of some kind and then the copying. But I have little to no clue on how
to make it happen.
Any ideas ?
Thanks a lot !
/Otto Blomqvist
From: | Gaetano Mendola <mendola(at)bigfoot(dot)com> |
---|---|
To: | Otto Blomqvist <o(dot)blomqvist(at)secomintl(dot)com> |
Subject: | Re: Copy data from one table to another, where some records might |
Date: | 2004-08-10 17:46:53 |
Message-ID: | 41190A0D.8070601@bigfoot.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Otto Blomqvist wrote:
> Hello !
>
> I have two tables with identical schema. I want to copy all data from
> Table A to Table B, but table B might already have some of table A:s
> data (each record is identified using record_numbers). I would suspect
> this can be accomlished using a 2 stage query, first performing a join
> of some kind and then the copying. But I have little to no clue on how
> to make it happen.
>
> Any ideas ?
This shall help you:
regression=# create table A ( fa1 integer, fa2 integer );
CREATE TABLE
regression=# create table B ( fb1 integer, fb2 integer );
CREATE TABLE
regression=# insert into B
regression-# select fa1, fa2 from A
regression-# where (fa1, fa2) not in (
regression(# select fa1, fa2 from B );
INSERT 0 0
Regards
Gaetano Mendola