List:General Discussion« Previous MessageNext Message »
From:Andrew Braithwaite Date:May 15 2009 2:11pm
Subject:RE: Inserting a default null date
View as plain text  
Agreed.  And don't forget to listen to the warnings MySQL sends back,

mysql> create table temp_date(d date default null);
Query OK, 0 rows affected (0.15 sec)

mysql> insert into temp_date(d) values('2009-13-99');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> show warnings;
| Level   | Code | Message                                |
| Warning | 1265 | Data truncated for column 'd' at row 1 | 
1 row in set (0.00 sec)

mysql> select * from temp_date;
| d          |
| 0000-00-00 | 
1 row in set (0.01 sec)


-----Original Message-----
From: Martijn Tonies [mailto:m.tonies@stripped] 
Sent: 15 May 2009 14:43
To: mysql@stripped
Subject: Re: Inserting a default null date 


> I have a table with a column like:
> date date default null,
> If I enter an empty string in it, the default null value is added (as
> should).
> But if I enter an invalid date by mistake, the date 0000-00-00 date
> is entered instead of the default null, and this is not good.
> Can I do something to force MySQL to insert a null date if the entered

> date is an invalid one?

That's silly, if the data you want to insert is considered to be
reject it,
don't replace it with NULL.

With regards,

Martijn Tonies
Upscene Productions

Download FREE! Database Workbench Lite for MySQL!

Database questions? Check the forum: 

MySQL General Mailing List
For list archives:
To unsubscribe:

Inserting a default null date Octavian Rasnita15 May
  • Re: Inserting a default null dateJanek Bogucki15 May
  • Re: Inserting a default null date Martijn Tonies15 May
    • RE: Inserting a default null date Andrew Braithwaite15 May