go-sql-driver/mysql — pull request #147 by julienschmidt (2013-10-31 10:32:06+00:00)
Title: Insert NULL for []byte(nil) values

This patch makes a behavior change for *inserting* data into a database:

Currently `[]byte(nil)` is treated the same way as `[]byte{}` / `[]byte("")`, which equals an empty string.This relies on the current language specification: http://golang.org/ref/spec

This PR changes to behavior to treat `[]byte(nil)` as nil values, therefore the same way as `interface{}(nil)`.
Here is why:

* **The specification is wrong**: The current implementation differs from the specification: http://play.golang.org/p/-OsXAW7tz9. Following the discussion at https://groups.google.com/forum/#!topic/golang-nuts/uhvxy5nOs5g the specification was changed: https://code.google.com/p/go/source/detail?r=fe0159f8fd43 (will be updated with the Go 1.2 release).

* **The current behavior is inconsistent**: Data *read* from the database is treated differently: https://code.google.com/p/go/source/browse/src/pkg/database/sql/convert.go#85
Both `[]byte(nil)` and `interface{}(nil)` are converted to `[]byte(nil)` by the database/sql package if the destination has the type `[]byte`. This matches the new behavior.

Fixes #144