On Fri, 12 Apr 2002, Steve Katen wrote:

> Ruben,
>
> If you leave it as NOT NULL it should default to NO.  "If an ENUM is
> declared NOT NULL, the default value is the first element of the list of
> allowed values."
>
> SIDE QUESTION:
> Are you doing something like: select * from table where enum_colum="NO"
>
> If you are running that type of query it won't work because enum does not
> store the values you put in.  it stores an index.

Huh?  It works for me (in 3.23.44).  Consider

mysql> CREATE TABLE enum_test (
    ->    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->    enum_column ENUM('No','Yes') NOT NULL,
    ->    PRIMARY KEY  (id)
    ->    );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO enum_test (enum_column)
    -> VALUES ('No'), ('Yes'), ('Yes'), ('No'), ('No'), ('No'), ('Yes');
Query OK, 7 rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM enum_test WHERE enum_column='No';
+----+-------------+
| id | enum_column |
+----+-------------+
|  1 | No          |
|  4 | No          |
|  5 | No          |
|  6 | No          |
+----+-------------+
4 rows in set (0.00 sec)

I don't think enums would be very useful if this weren't the case.

Of course, the manual <http://www.mysql.com/doc/E/N/ENUM.html> is very
unclear on this.  It's so busy explaining the the special cases (NULL,
invalid insert, numerical value, sorting, etc.) that it does not give a
single example of using the enumerated values in a select or insert.
That should probably be remedied.

Michael


---------------------------------------------------------------------
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