MySQL Forums
Forum List  »  MySQL Workbench

Re: I want Null not 0
Posted by: alan scott
Date: April 18, 2022 03:32PM


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

Will do in future.


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.)

I've done that already and as you say it's a real pain. Hence wondering if there was a way to avoid it.


That's an argument for scripting this input step in a complete language for which there's a MySQL API, eg PHP.

I've been managing my whisky collection through Excel but in my previous life I've seen the power of SQL and as a little intellectual challenge I wanted to learn My SQL and port my data over to it. Would this book be reasonable for picking up 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.

I do want it to be permanent so I'll give your suggestion a go tomorrow. Monstrosity seems harsh but in the circumstances fair.


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.
Once my PHP is up and running I'll never look at Notebook again but in the meantime I'll check out the charsets.

Thank you for all of your help.

Options: ReplyQuote

Written By
April 17, 2022 03:51PM
April 17, 2022 05:00PM
April 18, 2022 12:56AM
April 18, 2022 12:12PM
Re: I want Null not 0
April 18, 2022 03:32PM
April 18, 2022 04:46PM

Sorry, you can't reply to this topic. It has been closed.

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.