2

I have the following query, all the '' come up as empty strings

INSERT INTO `locations` ( `house`,`house_number`,`road`,`city`,`state`,`country`,`country_code`,`supermarket`,`county`,`place_of_worship`,`city_district`,`suburb`,`neighbourhood`,`pedestrian`,`postcode`) 
VALUES ('','','','Gemeinde Wien','Vienna','Austria','at','','W','Saint Stephen\'s cathedral','Innere Stadt','Innere Stadt','Textilviertel','Stephansplatz','1010');

table structure

All fields have a default value of null.

problem

So the question is, how can I get it so that empty strings keep their default value?

2
  • You will need to either insert a value of NULL or modify your query to not insert anything for those columns if there is no value Commented May 21, 2014 at 17:52
  • Bummer, I had hoped mysql could take care of it :) Lazy php right here! Commented May 21, 2014 at 18:00

1 Answer 1

3

Instead of inserting '' you can just use null

INSERT INTO`locations`(`house`,`house_number`,`road`,`city`,`state`,`country`,`country_code`,`supermarket`,`county`,`place_of_worship`,`city_district`,`suburb`,`neighbourhood`,`pedestrian`,`postcode`) 
VALUES (null,null,null,'Gemeinde Wien','Vienna','Austria','at','','W','Saint Stephen\'s cathedral','Innere Stadt','Innere Stadt','Textilviertel','Stephansplatz','1010');

or do not insert anything like this

INSERT INTO `locations` (`city`,`state`,`country`,`country_code`,`supermarket`,`county`,`place_of_worship`,`city_district`,`suburb`,`neighbourhood`,`pedestrian`,`postcode`) 
VALUES ('Gemeinde Wien','Vienna','Austria','at','','W','Saint Stephen\'s cathedral','Innere Stadt','Innere Stadt','Textilviertel','Stephansplatz','1010');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.