Unix Technical Forum

default, Nullable and NULL : confused

This is a discussion on default, Nullable and NULL : confused within the MySQL General forum forums, part of the MySQL category; --> Hello, I do not understand the behavior of a simple table : from what I red, in the following ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-18-2008, 10:48 AM
Gilles MISSONNIER
 
Posts: n/a
Default default, Nullable and NULL : confused

Hello,

I do not understand the behavior of a simple table :
from what I red, in the following exemple the Null column tells the value
can be set to NULL, and the Default value is NULL.
It doesn't seem to work that way.

Some one could explain it ?
I run on a linux debian/etch 5.0.32 MySQL release.


I have a table named "t" like :

mysql> describe t;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| n | double | YES | | NULL | |
| c | varchar(5) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+

Now I load data infile like this :
load data infile'/data/foo' into table t fields terminated by';';

with /data/foo containing :
0.12345;qwer
1.2345;
;asdf

I get
Records: 3 Deleted: 0 Skipped: 0 Warnings: 1

mysql> show warnings;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1265 | Data truncated for column 'n' at row 3 |
+---------+------+----------------------------------------+

from now, I expect to have NULL where the fields are empty, but
instead I get
'' in the 2nd row, columb 'c'
'0' in the last row, column 'n'

mysql> select * from t;
+---------+------+
| n | c |
+---------+------+
| 0.12345 | qwer |
| 1.2345 | |
| 0 | asdf |
+---------+------+


mysql> select * from t where c is null or n is null;
Empty set (0.00 sec)

For my purpose, '0' , '' and NULL

Thank you for any help.
regards,

_-¯-_-¯-_-¯-_-¯-_
Gilles Missonnier
IAP - gimi@iap.fr
01 44 32 81 36
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-18-2008, 10:48 AM
Ananda Kumar
 
Posts: n/a
Default Re: default, Nullable and NULL : confused

in your data file use this for inserting null values '\N'

0.12345;qwer
1.2345;\N
\N;asdf



On 7/17/08, Gilles MISSONNIER <gimi@iap.fr> wrote:
>
> Hello,
>
> I do not understand the behavior of a simple table :
> from what I red, in the following exemple the Null column tells the value
> can be set to NULL, and the Default value is NULL.
> It doesn't seem to work that way.
>
> Some one could explain it ?
> I run on a linux debian/etch 5.0.32 MySQL release.
>
>
> I have a table named "t" like :
>
> mysql> describe t;
> +-------+------------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +-------+------------+------+-----+---------+-------+
> | n | double | YES | | NULL | |
> | c | varchar(5) | YES | | NULL | |
> +-------+------------+------+-----+---------+-------+
>
> Now I load data infile like this :
> load data infile'/data/foo' into table t fields terminated by';';
>
> with /data/foo containing :
> 0.12345;qwer
> 1.2345;
> ;asdf
>
> I get
> Records: 3 Deleted: 0 Skipped: 0 Warnings: 1
>
> mysql> show warnings;
> +---------+------+----------------------------------------+
> | Level | Code | Message |
> +---------+------+----------------------------------------+
> | Warning | 1265 | Data truncated for column 'n' at row 3 |
> +---------+------+----------------------------------------+
>
> from now, I expect to have NULL where the fields are empty, but
> instead I get
> '' in the 2nd row, columb 'c' '0' in the last row, column 'n'
>
> mysql> select * from t;
> +---------+------+
> | n | c |
> +---------+------+
> | 0.12345 | qwer |
> | 1.2345 | |
> | 0 | asdf |
> +---------+------+
>
>
> mysql> select * from t where c is null or n is null;
> Empty set (0.00 sec)
>
> For my purpose, '0' , '' and NULL
>
> Thank you for any help.
> regards,
>
> _-¯-_-¯-_-¯-_-¯-_
> Gilles Missonnier
> IAP - gimi@iap.fr
> 01 44 32 81 36
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=anandkl@gmail.com
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:51 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com