Solved

MySQL importing empty values default to 0

Posted on 2010-08-29
5
923 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

937 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

4 Experts available now in Live!

Get 1:1 Help Now