Skip site navigation (1) Skip section navigation (2)


From: Andrei Ivanov <andrei(dot)ivanov(at)ines(dot)ro>
To: pgsql-novice(at)postgresql(dot)org
Subject: advice
Date: 2003-10-22 19:58:12
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
I have 2 tables with identical schemas.
What I have to do is insert in the 1st table all the rows from the 
2nd table that don't exist in the 1st.

I'm planning to something like 
INSERT INTO first_table 
  SELECT * FROM second_table s WHERE 
     NOT EXISTS (SELECT 1 FROM first_table WHERE id =

but I'm not sure this is the best way to do it...

Would anyone care to suggest a better query to do this ?

Thank you.


  • Re: advice at 2003-10-22 20:27:25 from Josh Berkus
  • Re: advice at 2003-10-25 20:31:52 from Paul Ganainm

pgsql-novice by date

Next:From: Josh BerkusDate: 2003-10-22 20:22:26
Subject: Re: Expressional Indexes
Previous:From: Tom LaneDate: 2003-10-22 19:44:58
Subject: Re: Expressional Indexes

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group