On Tue, 12 Mar 2002, James.FitzGibbon wrote:

> How big is the table?  i.e. if this is happening nightly, is it
> prohibitively expensive to do this:

The table is pretty small

> my $users_in_mysql = $mysql_dbh->selectall_hashref("SELECT ID FROM
> SOME_TABLE", "ID");
>
> while( ($first_name, $id) = $sel->fetch ) {
>       if( exists $users_in_mysql->{$id} ) {
>               # do update
>       } else {
>               # do insert
>       }
> }

That should work.  I got several replies in the last 20 minutes. Some
other suggestions that should work as well:

1) Use REPLACE instead of INSERT/UPDATE. That is MySQL specific but will
work great for me

2) Use the UPDATE inside my loop and then check the return value to see if
the row got updated. If not, use the INSERT.

I'll do some testing on these ideas.

Thanks everybody!

Tim

Tim Carlson
Voice: (509) 376 3423
Email: [EMAIL PROTECTED]
EMSL UNIX System Support


Reply via email to