0

I wanted to create a row with certain attributes:

querycurs.execute("CREATE TABLE CME_Equities(Contract Size TEXT, Contract Months TEXT")

However, I get an error with the names since they both start with "Contract", is there a way to force it to accept?

1 Answer 1

1

When your column names contain whitespace you need to put quotes around the names; you are also missing a closing parenthesis:

CREATE TABLE CME_Equities('Contract Size' TEXT, 'Contract Months' TEXT)

Quick demo with the sqlite3 command line utility:

$ sqlite3 :memory:
SQLite version 3.7.16.1 2013-03-29 13:44:34
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE CME_Equities('Contract Size' TEXT, 'Contract Months' TEXT);
sqlite> .schema
CREATE TABLE CME_Equities('Contract Size' TEXT, 'Contract Months' TEXT);

or the python version:

querycurs.execute("CREATE TABLE CME_Equities('Contract Size' TEXT, 'Contract Months' TEXT)")
Sign up to request clarification or add additional context in comments.

3 Comments

I was following a tutorial online and they inserted into tables like this: cur.execute("INSERT INTO Friends(Name) VALUES ('Tom');"), however, when I try a similar approach: querycurs.execute("INSERT INTO CME_Equities(elem) VALUES (cell_in_table);"), I get an error: OperationalError: no such column: cell_in_table. I thought the column is next to the name of table and values right after VALUES
You'll need to follow some more SQL tutorials; when inserting a value, you can not only insert literal values, but also data from other SQL expressions. cell_in_table is seen as an expression, not a value, because you didn't use quotes.
The Python equivalent would be to use foobar = somevalue instead of foobar = 'somevalue'; in the first example somevalue would be interpreted as the name of another object, but 'somevalue' is a string literal.

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.