Siegfried Heintze wrote:

Sorry, I accidentally pasted some garbage at the beginning of that last
email message. Here is what I intended:

I first check to see if the record exists:
SELECT cJobTitle FROM jobtitlecount WHERE fkJobPosting = 209689 AND
dtSnapShot = '2005-06-26'

When I don't find an entry, I try an insert:

INSERT INTO jobtitlecount (fkJobPosting, dtSnapShot, cJobTitle) VALUES
(209689,'2005-06-26',1)

The execute function indicated success.

But then  (sometimes) it tells me I have a duplicate entry:

DBD::mysql::st execute failed: Duplicate entry '209689-2005-06-26' for key 1
at ./crawl-hot-jobs.pl line 675.

How could this be?

Either you incorrectly interpreted the SELECT result, or someone/something inserted a row into the table between your SELECT and your INSERT, or one of your queries isn't what you think it is. It would help if you would show us your real code (not an edited version).

Now here is another example where I detect a duplicate and delete the
statement before trying to insert:

DELETE jobtitlecount WHERE dtSnapShot ='2005-06-26' AND fkJobPosting =
211151

DBD::mysql::st execute failed: You have an error in your SQL syntax.  Check
the manual that corresponds to your MySQL server version for the right
syntax to use near 'WHERE dtSnapShot ='2005-06-26' AND fkJobPosting =
211151' at li at ./crawl-hot-jobs.pl line 686.

I don't see any syntax error in that DELETE statement: do you?

Yes. The syntax is "DELETE FROM tablename ...". You are missing the "FROM". See the manual for details <http://dev.mysql.com/doc/mysql/en/delete.html>.

The primary key consists of two fields: fkJobPosting (integer) and
dtSnapshot (date).

Now if my SQL had a syntax error, would it not give me an error every time?
So why do I get "syntax" error?

I don't get a syntax error every time. These errors are very eratic and I
cannot discern what is different when these errors occur.

Thanks,
Siegfried
-----------------------------------------------------------------------

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to