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

copying tables

From: Robert Kernell <kernell(at)sundog(dot)larc(dot)nasa(dot)gov>
To: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org, dbi-users-subscribe(at)perl(dot)org
Subject: copying tables
Date: 2001-02-20 15:51:01
Message-ID: 200102201551.KAA02865@sundog.larc.nasa.gov (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
Hi. I am trying to copy tables. I want to copy a table in one database to a 
table in another database. The tables are identical. Here is to code and the 
error when using DBI. Can I just use postgresQL somehow?

Thank you.

Table    = fs648
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                | Length|
+----------------------------------+----------------------------------+-------+
| day                              | text                             |   var |
| type                             | text                             |   var |
| flight                           | text                             |   var |
| scene                            | text                             |   var |
| pattern                          | int4                             |     4 |
| leg                              | text                             |   var |
| id                               | int4 not null                    |     4 |
+----------------------------------+----------------------------------+-------+

#!/usr/bin/perl -wT

use strict;
use DBI;

my $dbh = DBI->connect("dbi:Pg:dbname=misr_l1; 
   host=sundog.larc.nasa.gov;port=5432", "", "") 
   or die "Can't connect\n";                      #connect to database
my $sth = $dbh->prepare("SELECT * from fs648");
$sth->execute();
my $array_ref = $sth->fetchall_arrayref();
$sth->finish;
$dbh->disconnect or warn "Disconnection failed\n";
 $dbh = DBI->connect("dbi:Pg:dbname=misr_l0; 
   host=sundog.larc.nasa.gov;port=5432", "", "") 
   or die "Can't connect\n";                     #connect to database
foreach my $row ($array_ref)
{  my ($day, $type, $flight, $scene, $pattern, $leg, $id) = @$row;
   my $dayq = $dbh->quote($day);
   my $typeq = $dbh->quote($type);
   my $flightq = $dbh->quote($flight);
   my $sceneq = $dbh->quote($scene);
   my $legq = $dbh->quote($leg);
   my $rows = $dbh->do("INSERT INTO fs648 VALUES ( $dayq, $typeq,
      $flightq, $sceneq, $pattern, $legq, $id)");
}
$dbh->disconnect or warn "Disconnection failed\n";

DBD::Pg::db do failed: ERROR:  parser: parse error at or near "xe1154"

$pattern and $id are integers and so don't need quoting. It doesn't work if I 
quote them anyway.

Thanks again!

Bob Kernell
Research Scientist
Analytical Services & Materials, Inc.
NASA Atmospheric Sciences Competency
Radiation and Aerolsols Branch
email: r(dot)w(dot)kernell(at)larc(dot)nasa(dot)gov
tel: 757-827-4631


Responses

pgsql-novice by date

Next:From: Richard EhrlichDate: 2001-02-20 20:08:53
Subject: Printing PostgreSQL reports
Previous:From: kspragueDate: 2001-02-20 14:01:51
Subject: 7.0.3 OK on solaris 2.8

pgsql-general by date

Next:From: Brent R. MatzelleDate: 2001-02-20 15:59:20
Subject: Re: How do I change data type from text to bool?
Previous:From: Brent R. MatzelleDate: 2001-02-20 15:36:12
Subject: Re: max / min explain

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