View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 07:37 AM
Bill Karwin
 
Posts: n/a
Default Re: Trouble with truncation error when loading data from a file

Ted wrote:
> The second column in the first table is a date with the format
> mm/dd/yyyy. We discussed this particular problem before. What I don't
> understand is that when loading this data into a table where everything
> is defined to be a varchar field, why would it care what the date
> format is. Should it not just treat that date field as any other
> string?


That is indeed odd. What error does it give?
Can you insert one record to the table manually with an INSERT
statement, using the values from one of the rows of the input file?

Does this still get an error if you use a non-MEMORY table? A
non-TEMPORARY table?

> As it is, no data gets loaded into the temporary tables.
>
> Do you have any simple examples of the perl scripts or "cleanup in SQL
> expressions" you mention?


Something like the following (off the cuff, not tested).
Supply the database name, user, and password where you see "...".

#!perl -an

use DBI;

BEGIN {
my $dsn = $dsn = "DBI:mysql:database=...";
my $user = '...';
my $password = '...';
$dbh = DBI->connect($dsn, $user, $password);
if (!defined($dbh)) {
die("Error:" . $DBI::errstr . "\n");
}
$sth = $dbh->prepare("INSERT INTO mytable (a, b, c) VALUES (?, ?, ?)");
if (!defined($sth)) {
die("Error:" . $dbh->errstr . "\n");
}
}

# Now the code executes for each line of input, thanks to "-n".
# @F is an array of the fields, auto-split by "-a".

# modify elements of the array, for instance
# reverse the characters of element 1:

$F[1] = reverse($F[1]);

# Execute our prepared INSERT statement, with the modified values:

$sth->execute(@F)
or die("Error:" . $dbh->errstr . "\n");

Regards,
Bill K.
Reply With Quote