Reputation: 395
I am trying some hands on with SQLite integrated with Python and am trying to insert values into the DB via a .csv file. I am getting the error: DUPLICATE COLUMN NAME : Measure. I think this is happening because two columns are starting with the same name. Any leads on where I am going wrong?
for row in reader:
if header:
header = False
sql_query = "DROP TABLE IF EXISTS %s" % tablename
cursor.execute(sql_query)
sql_query = "CREATE TABLE %s (%s)" % (tablename,
", ".join([ "%s TEXT" % col for col in row]))
cursor.execute(sql_query)
TRACEBACK ERROR:
File "C:\Users\Rachit-PC\AppData\Local\Continuum\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-107-6337a434d788>", line 32, in <module>
cursor.execute(sql_query)
sqlite3.OperationalError: duplicate column name: Measure
Upvotes: 3
Views: 9486
Reputation: 180070
CREATE TABLE va_ipshep_apr2017cms_09mar17 (
Provider ID TEXT,
Hospital Name TEXT,
...
The first column has the name Provider
, and the type ID TEXT
.
The second column has the name Hospital
, and the type Name TEXT
.
If you want to have special characters in the column names, you have to quote them:
CREATE TABLE va_ipshep_apr2017cms_09mar17 (
"Provider ID" TEXT,
"Hospital Name" TEXT,
...
Upvotes: 2