Solved

MySQL importing empty values default to 0

Posted on 2010-08-29
5
918 Views
Last Modified: 2012-05-10
I have the following field,
Field: field1
Type: DOUBLE
Length/Values:
Default: Null
Collation:
Attributes:
Null: TRUE

when I import an exported csv file from Microsoft Access with fieldtype value and default value nothing. For an empty(null) value, MySQL replaces it with 0, when obviously I want Empty/Null.
Because it is a number the csv just looks like ,,, as only text fields are quoted.

help appreciated


0
Comment
Question by:thydzik
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Rajesh Dalmia
ID: 33555810
u can run a update query after data import

Update Table set field1=NULL where field1 = 0
0
 
LVL 11

Author Comment

by:thydzik
ID: 33555829
Thanks, this is a good suggestion, but problem is there are actual 0 values which I need to keep.
I am thinking if I don't get a solution to change the values to text fields.
But I just don't understand why the default value of Null doesn't work, even when I check the Null tick-box.
0
 
LVL 11

Expert Comment

by:Rajesh Dalmia
ID: 33555856
if the value in csv file is empty then normal import will make that 0...
and anyway for field type double you should have a valid numeric value...
if u really want a NULL value also then you can do thing...
in csv you replace empty values with some other value like '-999' or anything else...something which after import will help you  identify...after import you can update that specific value with NULL value using query....
0
 
LVL 11

Accepted Solution

by:
thydzik earned 0 total points
ID: 33555905
yeh, the problem is MySQL needs a value of 'NULL' to make it a null value, but Access doesn't do this for Null values, it makes it an empty string on export.

I would either need to change the Number field to a Text field in access to allow a default value of 'NULL' to be present in the exported csv, or change the Number field to a Text field in MySQL to allow an empty string to be present in the csv file.
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33558727
convert your field to a varchar... then import your data.. then update your field to replace '' string value with NULL... then convert field back to integer...

update tableName set fieldName=NULL where fieldName='';
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Creating and Managing Databases with phpMyAdmin in cPanel.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now