in reply to DBD::Pg copy issues

Don't use prepare/execute. Use $dbh->func( ..., 'putline' ). DBD::Pg documents this. If this staill fails for you then attempt this using the standard psql client. If it still fails then there's something wrong with your data.

$db_input = "/tmp/snapshot_mil-newberlin1_cco.input"; $formName = ...; $dbh->func( "COPY snapshot_$formName (name, value, collect_date, omp_i +d) FROM '$db_input'", "putline" );

Replies are listed 'Best First'.
Re^2: DBD::Pg copy issues
by tradez (Pilgrim) on Sep 10, 2004 at 17:50 UTC
    Ok, but this still fails. Also, i notice in the documentation that "\." must be sent, how does one go about sending that?
    print INPUTFILE "\."; my $copySQL = "copy snapshot_$formName (name, value, collect_date, + omp_id) from '$db_input'"; $dbh->func("COPY snapshot_$formName (name, value, collect_date, om +p_id) FROM '$db_input'", "putline")
    is what i got, where am i wrong?


    Tradez
    "Never underestimate the predictability of stupidity"
    - Bullet Tooth Tony, Snatch (2001)

      If you already have the information inside perl here's an example. Be really careful to use only unix line endings - PostgreSQL's copy command is very particular about that.

      # Start copying some data to PostgeSQL. Here, STDIN is relative to the # script. So the PostgreSQL STDIN being mentioned is actually just the # stuff being written over $dbh->func( ..., 'putline'); $dbh->func( 'COPY some_table FROM STDIN', 'putline' ); # Write whatever was read from $fh to PostgreSQL's COPY. while ( <$fh> ) { chomp; $dbh->func( $_, 'putline' ); } # Tell PostgreSQL that the COPY is over with. $dbh->func( "\\.\n", 'putline' );
        K, I have this now
        $dbh->func('COPY snapshot_$formName (name, value, collect_date, omp +_id) from STDIN', 'putline'); print "Started a line\n"; foreach my $values (@form_out){ #my $cmd = `rm -f $form_out`; my @values = split(/;/, $values); my @names = split(/ /, $ga->{'outputString'}{$formName}); my $count = 0; $count = 0; foreach my $value (@values){ chomp($value); if (!$names[$count]){ print "$value element # $count does not exist in array\n"; } my $name = $names[$count]; chomp($name); $value =~ s/\s+/ / if $value; $value = 'Null' if (length($value) < '1'); if ($value =~ /\w+/){ $dbh->func("$name\t$value\t$date\t$ompId", 'putline'); }else{ $dbh->func("$name\tNull\t$date\t$ompId", 'putline'); } $count++; } } $dbh->func( "\\.\n", 'putline' ); print "ended that line\n";
        And i am still not getting inserts at all into the DB. What is the way to see what errStr has on the DBH obj, i tried like it was a STH and it didn't work.


        Tradez
        "Never underestimate the predictability of stupidity"
        - Bullet Tooth Tony, Snatch (2001)