List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 24 1999 9:24pm
Subject:RE: update? insert? Perl script
View as plain text  
At 4:55 PM -0400 8/24/99, Dan Ray wrote:
>Paul wrote:
>> if (defined ($yes)) # row exists
>> {
>> 	update
>> }
>> else                # row does not exist
>> {
>> 	insert
>> }
>
>I believe I may have stumbed across a better strategy than this. Anybody got
>any reason this wouldn't work?
>
>update
>get rows affected
>if (! rows affected) {
>	insert
>}
>
>In otherwords, just updating blindly, checking for effects, and inserting
>based on that. It's one fewer queries, certainly. Any downside to this?

If you happen to update to the same value, the row won't be considered
"affected" by MySQL and the row count will be zero.  Then you'll insert
another row.

-- 
Paul DuBois, paul@stripped
Thread
update? insert? Perl scriptgl324 Aug
  • Re: update? insert? Perl scriptJeff Beard24 Aug
  • Re: update? insert? Perl scriptPaul DuBois24 Aug
    • RE: update? insert? Perl scriptDan Ray24 Aug
      • Re: update? insert? Perl scriptThimble Smith24 Aug
      • RE: update? insert? Perl scriptgl324 Aug
      • Re: update? insert? Perl scriptScott Hess24 Aug
      • RE: update? insert? Perl scriptPaul DuBois24 Aug
        • RE: update? insert? Perl scriptJay Miller24 Aug
          • RE: update? insert? Perl scriptMichael Widenius29 Aug
        • RE: update? insert? Perl scriptDan Ray25 Aug
  • Re: update? insert? Perl scriptB.W. McAdams24 Aug