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;
[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
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
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
[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
[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
[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
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
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
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
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:
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
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
--
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
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
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
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
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
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
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
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
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
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
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
24 matches
Mail list logo