I am confused about the way INSERT DELAYED reacts to setting an
auto_increment field to NULL. I am inserting records into a table where one
of the columns is auto_increment. Usually when setting the value of an
auto_increment field in an INSERT query I pass a value of NULL. When I do
the same thing with INSERT DELAYED, specifying NULL causes the query to
fail. However, not specifying the value of the field or specifying a value
of 0 appears to achieve the same end as specifying NULL and the query is
successful.  When describing the function of auto_increment, the MySQL
manual states, "When you insert a value of NULL (recommended) or 0 into an
AUTO_INCREMENT column, the column is set to value+1...". This leads me to
expect that specifying either NULL or 0 should behave the same, yet with
INSERT DELAYED they do not. Am I missing something?

OK when RowID is not specified:
INSERT DELAYED INTO Foo (RefID, RefDate, UID, VID)
  VALUES (85, "2001-3-7 20:03:57", NULL, "10384501535502");

OK when RowID is set to 0:
INSERT DELAYED INTO Foo (RowID, RefID, RefDate, UID, VID)
  VALUES (0, 85, "2001-3-7 20:09:51", NULL, "10384501535502");

FAILED when RowID is set to NULL:
INSERT DELAYED INTO Foo (RowID, RefID, RefDate, UID, VID)
  VALUES (NULL, 85, "2001-3-7 20:03:57", NULL, "10384501535502");
MySQL said: Column 'RowID' cannot be null (Errno=1048)

This is the table definition:

CREATE TABLE Foo (
   RowID int(11) NOT NULL auto_increment,
   RefID int(11) DEFAULT '0' NOT NULL,
   RefDate datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
   UID int(11) DEFAULT '0',
   VID bigint(20) DEFAULT '0',
   PRIMARY KEY (RowID),
   KEY RefID (RefID)
);


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to