James Hallen
James Hallen

Reputation: 5014

Duplicate column name error sqlite3 Python

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?

Upvotes: 0

Views: 3806

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1122392

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

Upvotes: 1

Related Questions