[Chicago-talk] postgres and COPY statements

Jim Thomason jthomasoniii at yahoo.com
Thu Dec 11 14:29:36 CST 2003


Anybody here successfully used DBD::Pg for a COPY
statement? I haven't had any luck tracking down docs
or examples, except for a very small one. I love the
fact that the pod says "ooh, just look at test.pl,
which we've included" which is dandy, except for the
fact that they didn't. Sigh.

Here's the relevant code snippet:  

my $copy_into_student_answers =
$dbh->prepare(<<"eSQL");
  COPY
   bm_student_answers
   (bm_publication_id, user_id, 
   school_id, bm_question_id, bm_answer_id)
  FROM 
   stdin
eSQL

$copy_into_student_answers->execute();
foreach (@insert) {
  my $ret = $dbh->func($_, 'putline');
  print "INSERT ($ret) $_";
};

my $r = $dbh->func("\\.\n", 'putline'); 
				$copy_into_student_answers->finish() || die
"SHIT!"; 


Everything works. Returns are always 1, no problems on
the prep or the exec, and then I get:

DBD::Pg::st execute failed: COPY state must be
terminated first at...

on my next sth execute. Which to me implies that
postgres isn't acknowledging the \. to terminate the
copy. changing to a single \. w/o newline or a \. with
2 newlines doesn't matter.

Incidentally, I also know that I can dump my output to
a file with the identical copy statement and it
succeeds.

So I'm stumped. Anybody have any suggestions?

-Jim....

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/



More information about the Chicago-talk mailing list