Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Handling Null Values in --batch mode

I have a table where some values are null.

mysql> select * from temp ;
+-----------+----------+----------+----------+-------+
| firstname | lastname | address1 | address2 | state |
+-----------+----------+----------+----------+-------+
| john      | wall     | NULL     | NULL     | CA    |
+-----------+----------+----------+----------+-------+
1 row in set (0.00 sec)

When I select from this table from commandline with --batch table and write it to file I get something like this

mysql -u**** -p**** --batch temp_work -e "select * from temp" > temp.tab 

cat temp.tab 
firstname   lastname    address1    address2    state
john    wall    NULL    NULL    CA

Is there a way to force mysql to print those NULL as \N instead so that it will be handled in proper way when I try to load the data back.

I do know the option of SELECT INTO OUTFILE where null will be written as \N, but I want to find a work around for this problem for various reasons.

Any help is greatly appreciated.

Thanks

like image 558
DBGirl Avatar asked Apr 25 '26 13:04

DBGirl


1 Answers

I think you can use ISNULL(myColumn, "with whatever value you want to replace null with "). Hope this helps.