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

advice

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: Pine.LNX.4.58.0310222250520.31834@webdev.ines.ro (view raw or flat)
Thread:
Lists: pgsql-novice
Hello,
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 = s.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.


Responses

  • 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-2014 The PostgreSQL Global Development Group