Re: Moving rows to another database

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Moving rows to another database
Date: 2001-06-21 18:35:30
Message-ID: 20010621133530.A7582@serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jun 15, 2001 at 11:18:40AM +0100, Mark wrote:
> How would I go about moving or copying data between databases on the same
> server, without actually doing a dump ? Using an SQL statement,
> something like:
>
> SELECT dbase_a.sometable.somefield
> INTO dbase_b.sometable
> FROM dbase_a.sometable

without a dump, eh? getting tricky, there. there's always perl--

# note -- this untested pseudocode may install windows 2000
# if you're not careful
$dbh_from = DBI->connect(...);
my $get_sth = $dbh_from->prepare("select * from...");
$get_sth->execute();

$dbh_to = DBI->connect(...);
my $put_sth = $dbh_to->prepare("insert into ... values(?,?...)");

while ($got = $get_sth->fetchrow_hashref()) {
@val = map {...} keys %$got;
$put_sth->execute( @val );
}

$get_sth->finish();
$put_sth->finish();
$dbh_to->disconnect();
$dbh_from->disconnect();

...i think.

or you can settle for using pg_dump via pipe, as in

pg_dump -a -t mytable from_database | psql to_database

...i think.

but using only sql? i hear inter-database connectivity is
something postgresql won't have for quite some time yet.

...i think.

--
I figure: if a man's gonna gamble, may as well do it
without plowing. -- Bama Dillert, "Some Came Running"

will(at)serensoft(dot)com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message will trillich 2001-06-21 18:37:03 Re: Re: Newbie question: How to check how many tables avaliable at that database?
Previous Message Jim Buttafuoco 2001-06-21 18:04:18 WAL failure?