Gideon
Gideon

Reputation: 1886

How can I insert values into a MySQL table which contain whitespaces

I am trying to create a large number of new records based around values which often contain whitespaces. When I run my query without any values with whitespaces it works fine.

I am running this query directly in MySQL workbench, rather than via php or other.

My code:

INSERT INTO my_table (`country`) 
VALUES 
(‘Benin’),
(‘Bolivia’),
(‘Botswana’),
(‘Burkina Faso’)

This returns the error:

Error Code 1064: Syntax error... check near "Faso"

i.e. it has a problem with the space.

What I have tried:

Replacing all the apostrophe like characters with all the other apostophe like characters (I'm sorry, I don't know the technical names for them all) but I have used:

''  "" `` ‘’

I have also tried to escpape the whitespace but that hasn't worked

Upvotes: 1

Views: 6754

Answers (3)

nanoalvarez
nanoalvarez

Reputation: 93

Try this

INSERT INTO my_table VALUES ('Benin', 'Bolivia', 'Botswana', 'Burkina Faso')

The type of the fields should be var char or text. It should work.

Upvotes: 0

Soumyadip
Soumyadip

Reputation: 11

Hope this will work for you :

INSERT INTO my_table ('country') 
VALUES ('Benin','Bolivia','Botswana','Burkina Faso')

Upvotes: 0

Carsten Massmann
Carsten Massmann

Reputation: 28226

You are using two different types of quotes (left and right of your values!

(‘Burkina Faso’)

do

('Burkina Faso')

instead. You can already see from the syntax highlighting on this page that your original quotes did not lead to the desired result, as string contents should be shown in a dark read colour here.

Upvotes: 1

Related Questions