Inserting records into a Table in Remote database from another table in remote database

This is a multi-part message in MIME format.

------_=_NextPart_001_01CA4E2F.7C00B41E
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi,



I am new to PostgreSQL. I am using PostgreSQL 8.4.



[Requirement]:

I want to move all the records from a table in a database say, 'db_one'
into a table in another database say, 'db_two'. This I need to do by
executing a stored function that I stored in the 'postgres' database.

How can I effectively do this?



[Additional information]

1. 'db_one' and 'db_two' are present in the same server (under
localhost:5432 ) as that of the 'postgres' database.

2. Table in both the databases db_one & db_two are identical (i.e.
has same number of columns, column name, type etc.).



Here's what I tried to do,



select dblink_connect('connection_to_db_one', 'host=3Dlocalhost port=3D54=
32
user=3Dpostgres dbname=3Ddb_one password=3D*****');

select dblink_connect('connection_to_db_two', 'host=3Dlocalhost port=3D54=
32
user=3Dpostgres dbname=3Ddb_two password=3D*******');



select * from dblink('connection_to_db_one','select * from
db_one_table') as temp_table(user_id integer,

"MinTimestamp" timestamp without time zone, "MaxTimestamp" timestamp
without time zone);



PERFORM dblink_exec('connection_to_db_two','insert into
db_two_table(temp_table)');



select dblink_disconnect('connection_to_db_one');

select dblink_disconnect('connection_to_db_two');





I attempted the above code snippet from inside a stored function and
happened to receive the following error:

ERROR: query has no destination for result data



Kindly provide any help/suggestions.



Thanks & Regards,

Vishnu S

***** Confidentiality Statement/Disclaimer *****

This message and any attachments is intended for the sole use of the inte=
nded recipient. It may contain confidential information. Any unauthorized=
use, dissemination or modification is strictly prohibited. If you are no=
t the intended recipient, please notify the sender immediately then delet=
e it from all your systems, and do not copy, use or print. Internet commu=
nications are not secure and it is the responsibility of the recipient to=
make sure that it is virus/malicious code exempt.

The company/sender cannot be responsible for any unauthorized alterations=
or modifications made to the contents. If you require any form of confir=
mation of the contents, please contact the company/sender. The company/se=
nder is not liable for any errors or omissions in the content of this mes=
sage.


------_=_NextPart_001_01CA4E2F.7C00B41E
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-mi=
crosoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:wo=
rd" xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D=
"http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3DGenerator content=3D"Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
[at] font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
[at] font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
[at] font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
[at] font-face
{font-family:"Goudy Old Style";
panose-1:2 2 5 2 5 3 5 2 3 3;}
[at] font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
=2EMsoChpDefault
{mso-style-type:export-only;}
[at] page Section1
{size:8.5in 11.0in;
margin:99.25pt 85.05pt 85.05pt 85.05pt;}
div.Section1
{page:Section1;}
/* List Definitions */
[at] list l0
{mso-list-id:894463489;
mso-list-type:hybrid;
mso-list-template-ids:1884686542 67698703 67698713 67698715 67698703 676=
98713 67698715 67698703 67698713 67698715;}
[at] list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal>Hi,<o:p></o:p></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal>I am new to  PostgreSQL. I am using PostgreSQL =
8.4. <o:p></o:p></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal>[<b>Requirement</b>]:<o:p></o:p></p>

<p class=3DMsoNormal>I want to move all the records from a table in a dat=
abase say,
‘db_one’  into a table in another database say, ‘d=
b_two’.
 This I need to do by executing a stored function that I stored in t=
he ‘postgres’
database.<o:p></o:p></p>

<p class=3DMsoNormal>How can I effectively do this?<o:p></o:p></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal>[<b>Additional information</b>]<o:p></o:p></p>

<p class=3DMsoListParagraph style=3D'text-indent:-.25in;mso-list:l0 level=
1 lfo1'><![if !supportLists]><span
style=3D'mso-list:Ignore'>1.<span style=3D'font:7.0pt "Times New Roman"'>=
      
</span></span><![endif]>‘db_one’  and ‘db_two̵=
7;  are
present in the same server (under localhost:5432 ) as that of the ‘=
postgres’
database.<o:p></o:p></p>

<p class=3DMsoListParagraph style=3D'text-indent:-.25in;mso-list:l0 level=
1 lfo1'><![if !supportLists]><span
style=3D'mso-list:Ignore'>2.<span style=3D'font:7.0pt "Times New Roman"'>=
      
</span></span><![endif]>Table in both the databases db_one & db_two a=
re identical
(i.e. has same number of columns, column name, type etc.).<o:p></o:p></p>=


<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal>Here’s what I tried to do,  <o:p></o:p></=
p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>select
dblink_connect('connection_to_db_one', 'host=3Dlocalhost port=3D5432 user=
=3Dpostgres
dbname=3Ddb_one password=3D*****');<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>select
dblink_connect('connection_to_db_two', 'host=3Dlocalhost port=3D5432 user=
=3Dpostgres
dbname=3Ddb_two password=3D*******');<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'><o:p> </o:p></spa=
n></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>select * from 
dblink('connection_to_db_one','select * from db_one_table') as
temp_table(user_id integer,<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>"MinTimestamp&quo=
t;
timestamp without time zone, "MaxTimestamp" timestamp without t=
ime
zone);<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'><o:p> </o:p></spa=
n></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>PERFORM
dblink_exec('connection_to_db_two','insert into db_two_table(temp_table)'=
);<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'><o:p> </o:p></spa=
n></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>select
dblink_disconnect('connection_to_db_one');<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'color:#7030A0'>select
dblink_disconnect('connection_to_db_two');<o:p></o:p></span></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal>I attempted the above code snippet from inside a sto=
red function
and happened to receive the  following  error:<o:p></o:p></p>

<p class=3DMsoNormal><span style=3D'color:red'>ERROR:  query has no
destination for result data<o:p></o:p></span></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal>Kindly provide any help/suggestions.<o:p></o:p></p>

<p class=3DMsoNormal><o:p> </o:p></p>

<p class=3DMsoNormal><span style=3D'font-family:"Goudy Old Style","serif"=
'>Thanks
& Regards,<o:p></o:p></span></p>

<p class=3DMsoNormal><span style=3D'font-family:"Goudy Old Style","serif"=
'>Vishnu S<o:p></o:p></span></p>

</div>

***** Confidentiality Statement/Disclaimer ***** <br><br>This message and=
any attachments is intended for the sole use of the intended recipient. =
It may contain confidential information. Any unauthorized use, disseminat=
ion or modification is strictly prohibited. If you are not the intended r=
ecipient, please notify the sender immediately then delete it from all yo=
ur systems, and do not copy, use or print. Internet communications are no=
t secure and it is the responsibility of the recipient to make sure that =
it is virus/malicious code exempt.<br><br>The company/sender cannot be re=
sponsible for any unauthorized alterations or modifications made to the c=
ontents. If you require any form of confirmation of the contents, please =
contact the company/sender. The company/sender is not liable for any erro=
rs or omissions in the content of this message.<br></body>

</html>


------_=_NextPart_001_01CA4E2F.7C00B41E--
vishnu.s [ Fr, 16 Oktober 2009 09:08 ] [ ID #2019463 ]
Datenbanken » gmane.comp.db.postgresql.admin » Inserting records into a Table in Remote database from another table in remote database

Vorheriges Thema: Error when running PG_DUMP
Nächstes Thema: vacuumdb in parallel