> This would be even faster if you could concatenate all of the elements
of
> @array into a single list then you could say:
>
> #My PERL skills are non existent so you need to write this part.
> #I am assuming that @array is holding a list of string values.
>
> foreach my $element (@array) {
> @araylist += "'" + $element + "',";
> }
> @arraylist = left(@arraylist, length(@arraylist) -1)
>
> #that's to remove the trailing comma at the end of the list
>
> my $sql = "select col2, col3, col4 from table1
>           where col1 IN (?)";
> my $sth = $dbh->prepare($sql);
> $sth->execute(@arraylist) or die $sth->errstr();
>

I've finally gotten around to this. It doesn't appear to be possible using a placeholder.

$list  # a string of an unknown number of CS numeric primary keys.

$sql = "insert into table2
       (col2, col3, ...)
       select col2, col3, ...
       from table1
       where id in (?)";
$sth = $dbh->prepare($sql);
$sth->execute($list) || die ...

This inserts only the first item from $list.
$sth->execute(2,4) complains about mismatched number of bind variables.
An array (@list) does the same thing (only worse:)
where id in ($list)" returns an SQL syntax error.

Should I just fall back or am I missing something?

foreach $item (@list) {
  $sql = "insert into table2 ...

Thanks,
Jon


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to