Enum default values

2004-01-05 Thread Richard Dyce
Hi, I'm having problems with setting default values for an enum. It's for a booking system, and I'm keeping track of which day a property starts a booking period. It's useful to have the enum in day order therefore. Omitting the prompts, here's what's happening; * drop table property;

RE: Enum default values

2004-01-05 Thread Jay Blanchard
[snip] insert into property values ('','Book-keeper\'s Cottage','Thu'); insert into property values ('','Inglenook Barn','Fri'); insert into property values ('','Maggie\'s House','Fri'); insert into property values ('','Riverside View',''); insert into property values ('','The Manse',''); insert

Re: Enum default values

2004-01-05 Thread Richard Dyce
Jay! Thanks for help with a 'proper' insert. ;-) Yes, the full statement works fine. (I assume this is something like the not setting default values from importing DATA files?) All a bit of a shame, as I'm executing the insert from a PHP script, and was trying to make the routine as generic

Re: Enum default values

2004-01-05 Thread Martijn Tonies
Hi, [snip] insert into property values ('','Book-keeper\'s Cottage','Thu'); insert into property values ('','Inglenook Barn','Fri'); insert into property values ('','Maggie\'s House','Fri'); insert into property values ('','Riverside View',''); insert into property values ('','The

RE: Enum default values

2004-01-05 Thread Jay Blanchard
[snip] Yes, the DEFAULT doesn't apply. However, shouldn't MySQL raise an exception because '' isn't a valid value for this ENUM specification? [/snip] From http://www.mysql.com/doc/en/ENUM.html The value may also be the empty string () or NULL under certain circumstances: If you insert an

Re: Enum default values

2004-01-05 Thread Martijn Tonies
[snip] Yes, the DEFAULT doesn't apply. However, shouldn't MySQL raise an exception because '' isn't a valid value for this ENUM specification? [/snip] From http://www.mysql.com/doc/en/ENUM.html The value may also be the empty string () or NULL under certain circumstances: If you

RE: Enum default values

2004-01-05 Thread Jay Blanchard
[snip] 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

Re: Enum default values

2004-01-05 Thread Martijn Tonies
Hi, [snip] 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

Re: Enum default values

2004-01-05 Thread Michael Stassen
Martijn Tonies wrote: Hi, [snip] 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

Re: Enum default values

2004-01-05 Thread Martijn Tonies
Hi, This usually comes up when people expect an exception to be thrown when they assign NULL to a NOT NULL column, but this is the same idea. From the manual http://www.mysql.com/doc/en/constraint_NOT_NULL.html: Indeed. One of those weird MySQL things. Is this different on InnoDB? To be

Re[2]: Enum default values

2004-01-05 Thread Aleksandar Bradaric
Hi, I will now have to supply a field list to the function in addition. Ah well ;-) Maybe this help: insert into `property` values ('', 'Riverside View', default); Take care, Aleksandar -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:

Re: Re[2]: Enum default values

2004-01-05 Thread Richard Dyce
Ah ha! Thank you Aleksandar. That's a much better solution. In fact, now youv'e told me this, I looked in the Manual, and the scales where lifted from my eyes. You've saved me re-writing (and re-thinking) a large chunk of PHP. For anyone else's future reference it's all there in plain english

Re: ENUM Default values on NULL

2002-04-12 Thread Ruben I Safir
sql Hello I need a ENUM to default to a value when it gets a NULL. Can this be done. Right now is I set the column to FIELD ENUM('NO','YES') NOT NULL It fails to insert when a NULL is entered. I want it to default to NO Can I set it to do this? Ruben --

Re: ENUM Default values on NULL

2002-04-12 Thread Steve Katen
ENUM can handle your needs. you should be able to just change your syntax to: FIELD ENUM('NO','YES') NULL under that syntax your default value will be NULL. this is from the documentation directly: If an ENUM is declared NULL, NULL is also a legal value for the column, and the default value

Re: ENUM Default values on NULL

2002-04-12 Thread Ruben I Safir
ENUM can handle your needs. you should be able to just change your syntax to: FIELD ENUM('NO','YES') NULL under that syntax your default value will be NULL. We need it to default to 'NO' not NULL sql Ruben - Before

Re: ENUM Default values on NULL

2002-04-12 Thread Ruben I Safir
sql ENUM can handle your needs. you should be able to just change your syntax to: FIELD ENUM('NO','YES') NULL under that syntax your default value will be NULL. I need it to default to 'NO' not NULL - Before

Re: ENUM Default values on NULL

2002-04-12 Thread Steve Katen
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

Re: ENUM Default values on NULL

2002-04-12 Thread Ruben I Safir
When I send a NULL it's rejected as bad data, which sort of makes sense On 2002.04.12 12:33 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. The

Re: ENUM Default values on NULL

2002-04-12 Thread Gerald Clark
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

Re: ENUM Default values on NULL

2002-04-12 Thread Steve Katen
Ruben, 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. it is inserting the value as the first value in the table which is the error value or the index of 0. i would

Re: ENUM Default values on NULL

2002-04-12 Thread Michael Stassen
Instead of inserting NULL, leave the column out. INSERT mytable (2nd_col_name) VALUES (NULL); If you don't mention the enum column, it gets the default. Michael On Fri, 12 Apr 2002, Ruben I Safir wrote: When I send a NULL it's rejected as bad data, which sort of makes sense On

Re: ENUM Default values on NULL

2002-04-12 Thread Michael Stassen
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

Re: ENUM Default values on NULL

2002-04-12 Thread Ruben I Safir
Your example is not the same, it sends only one value to a 2 value table. It definetely does not work if you send NULL INSERT VALUES(NULL) Ruben On 2002.04.12 14:10 Michael Stassen wrote: On Fri, 12 Apr 2002, Steve Katen wrote: Ruben, If you leave it as NOT NULL it should default

Re: ENUM Default values on NULL

2002-04-12 Thread Michael Stassen
Ruben, I think youare referring to my earlier message, but no matter. You cannot insert NULL into a column you've defined as NOT NULL, with some special exceptions (auto_increment and timestamp, for example). As I said before, if you want a column to get its default value, you leave it out of