Solved

MySQL importing empty values default to 0

Posted on 2010-08-29
5
928 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Choosing a MySQL HA Solution

Join Percona’s Principal Technical Services Engineer, Marcos Albe as he presents Choosing a MySQL High Availability Solution on Thursday, June 29, 2017 at 10:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

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

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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