Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Why not Replace?

by powerman (Friar)
on Apr 27, 2002 at 11:55 UTC ( [id://162505]=note: print w/replies, xml ) Need Help??


in reply to Database Update or Insert

Hmm..
Why not use REPLACE instead of UPDATE+INSERT?
The only problem with REPLACE is when you UPDATE not all fields in table, but for your example REPLACE is good.
$dbh->do("REPLACE INTO $table SET item_id=?, upc=?", undef, $item_id, $upc) or die $dbh->errstr;

Replies are listed 'Best First'.
Re: Why not Replace?
by asdfgroup (Beadle) on Apr 27, 2002 at 13:57 UTC
    This won't work because of 2 resons :

    1) This will work only for key field but this is not clear based on example item_id is keyfield

    2) record can have additional fields. All this fields after replace will be empty

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://162505]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found