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

Re: How to copy from Table to table

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: joseph antonyraj <josephtonyraj(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to copy from Table to table
Date: 2005-04-03 03:44:38
Message-ID: 20050403034438.GA30300@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-general
[Originally sent to pgsql-committers; I'm replying to pgsql-general.]

On Tue, Mar 29, 2005 at 01:20:02AM -0800, joseph antonyraj wrote:
>  
> I need your help to copy a table from a table through copy command
> using PostGresql command. Just for your information, both the tables
> will exists and will overwrite as on requirement.

What do you mean by "overwrite"?  Do you want to replace the entire
table?  Or do you want to keep existing records, add new records,
and update (overwrite) records that match some condition?

If you want to replace the entire table, then you can use TRUNCATE
or DELETE to empty it, then INSERT ... SELECT to insert the results
of a query.  Another possibility would be to DROP the table and use
CREATE TABLE AS or SELECT INTO, but then you'd have to recreate any
indexes, constraints, triggers, etc.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-committers by date

Next:From: Tom LaneDate: 2005-04-04 01:43:13
Subject: pgsql: In cost_mergejoin, the early-exit effect should not apply to the
Previous:From: Tom LaneDate: 2005-04-03 00:02:05
Subject: pgsql: Put back code mistakenly removed from copy of postmaster's

pgsql-general by date

Next:From: Tony CadutoDate: 2005-04-03 03:56:32
Subject: Re: PostgreSQL and .NET
Previous:From: Christopher Kings-LynneDate: 2005-04-03 02:55:18
Subject: Re: [HACKERS] plPHP in core?

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