MySQL Forums
Forum List  »  MySQL Workbench

Re: I want Null not 0
Posted by: Peter Brawley
Date: April 18, 2022 12:12PM

In these fora, enclose text whose formatting you wish to preserve inside BBCode code tags.

If the spreadsheet outputs spaces for missing values and you need nulls for missing values, you could import into variables ...

load data ...
...
columns(@col0, @col1, ...)
...
set col1=if(@col1=' ',null,@col1), etc ...

... for all columns, but you'll need to write that 132 times. (See the Load Data Infile manual page for examples.) That's an argument for scripting this input step in a complete language for which there's a MySQL API, eg PHP.

And if you're going to do that, and if the table here is meant as a permanent table for data analysis (rather than just sucking up spreadsheet data), consider fixing its design with something like ...

swa_averages ( bottle_id int unsigned, mo smallint unsigned, value unsigned, primary key(bottle_id,mo) )

... to dispense with the monstrosity of column names containing indexing digits.

Finally, if you must use Notepad (ugh) for handling text files coming into or out of MySQL, be sure to set its charset to what MySQL is using.



Edited 1 time(s). Last edit at 04/18/2022 12:12PM by Peter Brawley.

Options: ReplyQuote


Subject
Views
Written By
Posted
273
April 17, 2022 03:51PM
167
April 17, 2022 05:00PM
181
April 18, 2022 12:56AM
Re: I want Null not 0
164
April 18, 2022 12:12PM
169
April 18, 2022 03:32PM
146
April 18, 2022 04:46PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.