KBD

Keith Devens .com

Friday, July 4, 2008 Flag waving
Less isn't more; just enough is more. – Milton Glaser
← Entry 1439Entry 1441 →

Daily link icon Saturday, February 16, 2002

MySQL's crappy handling of default values

Dude, I just realized that MySQL's handling of default values sucks. A query I was writing kept failing and I didn't see what was wrong, so I took the query down to just one field. It succeeded, even though I hadn't specified values for NOT NULL fields. So I checked in phpMyAdmin, and it turns out a bunch of default values were set. I figured phpMyAdmin had set them without me telling it to.

So I took a dump of the SQL to create the table, took all the default values out, renamed the original table, and ran that SQL to recreate the table.

I ran the query with just one field again, and it succeeded! So, I got out my MySQL book, looked up "Default" in the index, turned to page 239, and found this in the section on the CREATE statement:

DEFAULT value
This attribute assigns a default value to a field. If a row is inserted into the table without a value for this field, this value will be inserted. If a default is not defined, a null value is inserted unless the field is defined as NOT NULL in which case MySQL picks a value based on the type of the field. (emphasis mine)

That's ridiculous!

← Entry 1439Entry 1441 →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

Girls, please don't get breast implants

> And no, you will not be receiving​a picture.

:-(...

Keith: Jul 2, 6:05am

Javascript clone function

This is a clever way to clone an​object if you are using YAHOO UI.​Same tec...

Antonio: Jul 1, 12:47pm

I hate Norton Antivirus

Oh just one other thing norton is​great at keeping people out of your​compu...

kevin.sands: Jul 1, 12:50am

Terminator 3 was awful

I think the biggest reason why T3​totally blew was because Edward​Furlong g...

76.167.172.64: Jun 29, 3:06am

Generated in about 0.105s.

(Used 8 db queries)

mobile phone