load data infile. Empty input field - integer. How make NULL ?

2005-05-29 Thread Pete Lancashire
I've been surfing the list / google but can't find what to do

I have a tab sep file, where there are empty fields i.e.
tabtab

the fields are associated with a mysql table integer type.

how do I get the empty fields to become NULL instead of
0 (zero) with a warning ?

Thanks,

-pete


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: load data infile. Empty input field - integer. How make NULL ?

2005-05-29 Thread mfatene
Hi,
If you let a tabulation, you will have 0 for numbers.
supposing this is the file tab.txt :
a 1   c
a c

mysql load data infile c:/tab.txt into table tab fields terminated by \t
enclosed by \ lines terminated by \r\n;
Query OK, 2 rows affected, 1 warning (0.00 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 1

mysql select * from tab;
+--+--+--+
| a| b| c|
+--+--+--+
| a|1 | c|
| a|0 | c|
+--+--+--+
2 rows in set (0.00 sec)


IF you want to handle NULL values, you must change empty values to \N :
*** new tab.txt
a 1   c
a \N  c


mysql load data infile c:/tab.txt into table tab fields terminated by \t
enclosed by \ lines terminated by \r\n;
Query OK, 2 rows affected (0.00 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 0

mysql select * from tab;
+--+--+--+
| a| b| c|
+--+--+--+
| a|1 | c|
| a| NULL | c|
+--+--+--+
2 rows in set (0.00 sec)



Mathias

Selon Pete Lancashire [EMAIL PROTECTED]:

 I've been surfing the list / google but can't find what to do

 I have a tab sep file, where there are empty fields i.e.
 tabtab

 the fields are associated with a mysql table integer type.

 how do I get the empty fields to become NULL instead of
 0 (zero) with a warning ?

 Thanks,

 -pete


 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]





-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]