Re: INSERT if record NOT EXISTS

2004-07-27 Thread Harald Fuchs
In article [EMAIL PROTECTED], Adaikalavan Ramasamy [EMAIL PROTECTED] writes: This seems more like the solution I want. I am using perl-DBI and when there is an error (i.e. duplicate insert), the rest of the scrip it not executed. But this is gives me the following error. What am I doing wrong

INSERT if record NOT EXISTS

2004-07-26 Thread Adaikalavan Ramasamy
I am creating a small database that keeps track of users and assigns them a unique user ID. The problem is that sometimes the users might request to be added more than once (i.e. click on the submit button multiple times). Therefore I only want to add users if their details (here defined by both

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Alec . Cawley
Adaikalavan Ramasamy [EMAIL PROTECTED] wrote on 26/07/2004 16:05:23: I am creating a small database that keeps track of users and assigns them a unique user ID. The problem is that sometimes the users might request to be added more than once (i.e. click on the submit button multiple

Re: INSERT if record NOT EXISTS

2004-07-26 Thread gerald_clark
Your model is flawed. My son and I have the same first and last names. Therefore, we could not be users on your system. Adaikalavan Ramasamy wrote: I am creating a small database that keeps track of users and assigns them a unique user ID. The problem is that sometimes the users might request to

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Adaikalavan Ramasamy
Thanks Alec ! This works wonderfully. But I have another related question. How do I write an IF ELSE command with MYSQL. In this context, I want it to return myID if the record already exists, otherwise insert into database. This naive syntax does not work : IF EXISTS (SELECT myID FROM tb WHERE

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Michael Dykman
from http://dev.mysql.com/doc/mysql/en/INSERT.html: 14.1.4 INSERT Syntax INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO] tbl_name [(col_name,...)] VALUES ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ] ... If you specify the ON DUPLICATE KEY UPDATE

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Adaikalavan Ramasamy
This seems more like the solution I want. I am using perl-DBI and when there is an error (i.e. duplicate insert), the rest of the scrip it not executed. But this is gives me the following error. What am I doing wrong ? mysql desc tb;

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Keith Ivey
Adaikalavan Ramasamy wrote: This naive syntax does not work : IF EXISTS (SELECT myID FROM tb WHERE firstname='Jack' AND lastname='Doe') ELSE (INSERT INTO tb(firstname, lastname) VALUES ('Jack', 'Doe'); Assuming you have the unique index on (firstname, lastname), just do INSERT IGNORE INTO tb

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Adaikalavan Ramasamy
Yes, this does what I want and does not produce an error (which caused the remaining MYSQL syntax not to be executed). The firstname, lastname was for example only. In my problem, these are two different identifiers so I am not worried about multiple dual identifiers. Thanks to Keith Ivey, Alec

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Alec . Cawley
Adaikalavan Ramasamy [EMAIL PROTECTED] wrote on 26/07/2004 16:31:44: But I have another related question. How do I write an IF ELSE command with MYSQL. In this context, I want it to return myID if the record already exists, otherwise insert into database. This naive syntax does not work

Re: INSERT if record NOT EXISTS

2004-07-26 Thread Marc Slemko
On Mon, 26 Jul 2004 17:47:37 +0100, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote: This seems more like the solution I want. I am using perl-DBI and when there is an error (i.e. duplicate insert), the rest of the scrip it not executed. But this is gives me the following error. What am I doing