0

I have a table with columns machine id like (311a__) and (311bb__) and some of them like (08576). How can I retrieve them in SQL - how to insert into row where machine ID is like ( 311a__)? My question how to insert and select a column which has spaces in it.. How to retrieve data where machine_name ="%s__" is it correct

sql_local = """SELECT id FROM customer_1.pay_machines WHERE machine_name="%s" """ % machine

  retVal = cursor.execute(sql_local)
  if (retVal == 0):
    sql_local = """INSERT INTO customer_1.pay_machines (machine_name, carpark_id) VALUES ("%s", 0)""" % machine
3
  • select 'column name with spaces',[column name with spaces] from table_name Commented Feb 26, 2014 at 13:00
  • You should use `field name` Commented Feb 26, 2014 at 13:00
  • 1
    I'm not sure what the question is, but your insert query is not valid sql. Commented Feb 26, 2014 at 13:01

1 Answer 1

2

Surround odd (or reserved word) column names with backticks:

SELECT * 
  FROM  pd 
 WHERE `machine id` = '(%s__)';

edit: removed invalid insert query as the first query is sufficient as an example

Sign up to request clarification or add additional context in comments.

1 Comment

If you are posting code, edit it for syntax errors. INSERT ... VALUES ... WHERE is not valid SQL.

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.