Ruben,

> I has a column defined as 
> enum not null (percent,absolute) default value percent (in psuedocode)
> and I was able to update a record which filled it either with a NULL or
> an empty string.

> How does this happen?  the value should be either percent or absolute,
>         or the update should just fail.

>From the manual:

If you insert an invalid value into an ENUM (that is, a string not
present in the list of allowed values), the empty string is inserted
instead as a special error value. This string can be distinguished
from a 'normal' empty string by the fact that this string has the
numerical value 0.

http://www.mysql.com/doc/en/ENUM.html

Furthermore, MySQL does only very basic checking of values. Here's an
example:

mysql> CREATE TABLE t_enum (
    ->  a ENUM('percent','absolute') NOT NULL DEFAULT 'percent'
    -> ) TYPE=MyISAM;
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO t_enum VALUES
    ->  ('percent'),('absolute'),('wrong_value'),(NULL)
    -> ;
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 2

mysql> SELECT * FROM t_enum;
+----------+
| a        |
+----------+
| percent  |
| absolute |
|          |
|          |
+----------+
4 rows in set (0.00 sec)

As you can see, the NULL value is treated as a wrong value (because
the column is declared NOT NULL), so it is inserted as an empty string
(the special error value).

Regards,
--
  Stefan Hinz <[EMAIL PROTECTED]>
  iConnect GmbH <http://iConnect.de>
  Heesestr. 6, 12169 Berlin (Germany)
  Telefon: +49 30 7970948-0  Fax: +49 30 7970948-3

[filter fodder: sql, mysql, query]


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

Reply via email to