Message-
From: Brent Baisley [mailto:[EMAIL PROTECTED]
Sent: 16 October 2003 19:29
To: Mike Tuller
Cc: MySql List
Subject: Re: Check for data before inserting
It sound like you want to use REPLACE instead of the SELECT and
INSERT/UPDATE combo. Replace will insert if the record doesn't exist
or primary key)
Thanks
Emery
- Original Message -
From: Mike Knox [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, October 17, 2003 09:44
Subject: RE: Check for data before inserting
Traditionally, I'd take the following approach
1) Update - assume it's there
2) If update fails (0
Mike Knox wrote:
Traditionally, I'd take the following approach
1) Update - assume it's there
2) If update fails (0 rows) do an insert
Thats assuming that the update case is more prevalent. If the row is
unlikely to be there - insert and do the update if you get a duplicate key.
You have
Why would the REPLACE statement not work?
Simon
(ps mite have missed some thing if so sorry)
-Original Message-
From: gerald_clark [mailto:[EMAIL PROTECTED]
Sent: 17 October 2003 14:08
To: Mike Knox
Cc: '[EMAIL PROTECTED]'
Subject: Re: Check for data before inserting
Mike Knox wrote
wrote:
Why would the REPLACE statement not work?
Simon
(ps mite have missed some thing if so sorry)
-Original Message-
From: gerald_clark [mailto:[EMAIL PROTECTED]
Sent: 17 October 2003 14:08
To: Mike Knox
Cc: '[EMAIL PROTECTED]'
Subject: Re: Check for data before inserting
Mike Knox
: Friday, October 17, 2003 15:44
Subject: Re: Check for data before inserting
I didn't say it wouldn't.
I was pointing out the danger of the method listed.
Also, a danger with replace is that multiple records might be deleted
for one insert if there are multiple unique keys in the table
)
Thanks
Emery
- Original Message -
From: Mike Knox [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, October 17, 2003 09:44
Subject: RE: Check for data before inserting
Traditionally, I'd take the following approach
1) Update - assume it's there
2) If update fails (0 rows) do an insert
I have a shell script that I have data entered into a database, and instead
of just entering in the data blindly, I want it to check to see if the item
it is entering exists already, and if it does, update the information rather
than inserting it. So I want to run a select statement, and if
It sound like you want to use REPLACE instead of the SELECT and
INSERT/UPDATE combo. Replace will insert if the record doesn't exist
and update if it does.
On Thursday, October 16, 2003, at 01:27 PM, Mike Tuller wrote:
I have a shell script that I have data entered into a database, and
, if
there is no match, then the data is inserted into a new row.
Mike
From: Brent Baisley [EMAIL PROTECTED]
Date: Thu, 16 Oct 2003 14:29:21 -0400
To: Mike Tuller [EMAIL PROTECTED]
Cc: MySql List [EMAIL PROTECTED]
Subject: Re: Check for data before inserting
It sound like you want to use REPLACE
actually it will act like insert in eather case. if its there,
delete it first, if not just insert.
http://www.mysql.com/doc/en/REPLACE.html
as far as using shell to do the insert/update, you could look at
command line php, that way you get the logic and you don't have to
learn a new
You are confusing the string function with the sql function.
Mike Tuller wrote:
Unless I am mistaken on REPLACE's use, I don't think that will work. The
example I have in the O'Reilly MySql book that I have shows this.
REPLACE(string, old, new)
Returns a string that has all occurances of the
12 matches
Mail list logo