$dbh->func( 'COPY snapshot_$formName ( name, value, collect_date, omp_ +id ) FROM STDIN', 'putline' );
There are three problems with preceding line.
my $count = 0; for ( ... ) { ... $names[ $count ] $count++; }
It looks like somehow your indexes in @values are synchronized with the indexes in some @names list. When you manage the current index manually, you make it likely that it will be managed incorrectly. Let perl do this for you.
foreach my $ix ( 0 .. $#names ) my $value = $values[ $ix ]; if ( ! $names[ $ix ] ) { } }
Now here's what I think a reasonable re-write of your code would look like. I didn't change the table attribute name so that's still present in its likely-buggy form.
$formName = ...; @form_out = ...; $ga = { ... }; $collect_date = ...; $omp_id = ...; my @value_names = split ' ', $ga->{ 'outputString'}{ $formName }; chomp @value_names; my $table_name = "snapshot_$formName"; $dbh->func( "COPY $table_name ( name, value, collect_date, omp_id ) FR +OM STDIN", "putline" ); print "Started a line.\n"; for my $packed_values ( @form_out ) { my @values = split /:/, $packed_values; my @values_to_use_ix = grep $value_names[ $_ ], 0 .. $#value_names; for my $ix ( @values_to_use_ix ) { my $value = $values[ $ix ]; my $value_name = $value_names[ $ix ]; $value = 'NULL' if not defined $value; $value =~ s/^\s+//; $value =~ s/\s+$//; # The following line will remove any internal tabs which would + mess with # the column count. $value =~ s/\s+/ /g; $value = 'NULL' if not length $value; my $row = join( "\t", $value_name, $value, $collect_date, $omp_id ); eval { $dbh->func( $row, 'putline' ) } or die "Couldn't write `$row' to $table_name: $@, " . $dbh +->errstr; } }
In reply to Re^5: DBD::Pg copy issues
by diotalevi
in thread DBD::Pg copy issues
by tradez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |