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

Re: Re: Copying data from one table of one database to other table f other database

From: "Preetam Palwe" <preetamp(at)aftek(dot)com>
To: "Jasen Betts" <jasen(at)xnet(dot)co(dot)nz>,<pgsql-novice(at)postgresql(dot)org>
Subject: Re: Re: Copying data from one table of one database to other table f other database
Date: 2009-04-28 13:55:58
Message-ID: D2885A8132EB554B854E9E017ED9FEAC144317@exbm.aftekpune.com (view raw or flat)
Thread:
Lists: pgsql-novice
Thanks folks!
Following command worked for me 


psql -h x.x.x.x -U postgres -d securez -c " copy  alerts to stdout "  |
psql -h x.x.x.x -U postgres -d p -c " copy alerts from stdin "

but 
psql -h x.x.x.x -U postgres -d securez -c " copy (select * from alerts)
to stdout "  | psql -h x.x.x.x -U postgres -d p -c " copy alerts from
stdin "

is giving me syntax error as 

ERROR:  syntax error at or near "("
LINE 1:  copy (select * from alerts) to stdout

Any idea ?
 


-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Jasen Betts
Sent: Tuesday, April 28, 2009 6:35 PM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] Re: Copying data from one table of one database to
other table f other database

On 2009-04-27, Preetam Palwe <preetamp(at)aftek(dot)com> wrote:
> This is a multi-part message in MIME format.

> Hello all
>
>                 I want to copy the data from one table to other table.
> These tables reside in two different databases.
>
> I am thinking of using following query=20
>
>
> insert into table2 (select * from table1)
>
>
> but the problem is how can I specify the database name?

you can't



you can do this however:

 psql -c " copy (select * from table1) to stdout " database1 | psql -c "
copy table2 from stdin " database2


In response to

Responses

pgsql-novice by date

Next:From: Neil SaundersDate: 2009-04-28 16:31:48
Subject: Query appears not to recognise index (enable_seqscan=off)
Previous:From: Jasen BettsDate: 2009-04-28 13:05:12
Subject: Re: Copying data from one table of one database to other table f other database

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