RE: Help: update record if existed, else insert it
Posted in 1996
Hi Chih Try doing this the other way round. Have a unique index on the table = that you want to update. First try to INSERT. If a record with the same = unique index values exists, it will generate an exception, and on = exception do the update. We have used this strategy succesfully at our = site.=20 The other more kludgy approach that we used before was to do a count(*) = for the given values. If count(*) > 0 then update else insert. We = stopped using this, because we were having locking problems and too many = sequential scans. We considered using DIRTY READ to solve the locking = problem but that may have given us wrong row counts. Hope this helps Sujit Pal DBA, Computer Sciences Corp. ---------- From: Chih-Cherng Chin[SMTP:c811052@bsdpc1.iii.org.tw] Sent: Sunday, September 29, 1996 7:08 PM To: informix-list@rmy.emory.edu Subject: Help: update record if existed, else insert it Hi all, Being new to SPL, and wanting to implement a SP to log hits, I'm having problems writing it. I want to do the following: 1. if the corresponding record exists, update its column, 2. if not, insert a new record. Originally, I thought about doing it this way: 1. Try to update the record, whether it exists or not, 2. if the update failed, use the exception to insert a new record. But it turns out that the failed update is not considered as a error, so I can't do that. I think there are many problems similar to this, so please share your experience. Thanks in advance. Chih-Cherng Chin elmo@iii.org.tw