0

For example, the code below runs well:

import sqlite3 as sq
ft=['Height', 'Weight', 'Skin', 'Face_Shape',]
rose=['five','onekilo','tan','long']
conn=sq.connect('ft.db')
cur=conn.cursor()
cur.execute("CREATE TABLE data(Height char(30), Weight char(30), Skin char(30), Face_Shape char(30))")
cur.execute("INSERT INTO data VALUES(?,?,?,?)",rose)
conn.commit()

I have a list containing two hundred values. How can I create a table with all of them as table columns; and is there an easy way to insert values, instead of writing two hundred "?" placeholders?

CL.
  • 173,858
  • 17
  • 217
  • 259
Biterk
  • 3
  • 2
  • @CL sorry typo corrected – Biterk Dec 10 '18 at 09:17
  • You have to construct the SQL commands in your code. – CL. Dec 10 '18 at 09:26
  • @PeterWood the quoted question is about insert multiple Entries in a three columns table. this one about creating a table with multiple(hundreds) columns and easy way to insert ONE Entry without writing hundreds question marks. – Biterk Dec 10 '18 at 09:31
  • 1
    You don't have to write out 200 question marks and commas by hand... Just write code that builds a string with them. Probably takes one line with python. – Shawn Dec 10 '18 at 09:42
  • 1
    Also, since you're using things like `char(30)`, you really should read this essential bit of documentation: https://www.sqlite.org/datatype3.html – Shawn Dec 10 '18 at 09:45

1 Answers1

0

I find the .join method is not a bad way.

strings="INSERT INTO data VALUES(%S)"%",".join(60*'?')
cursor.execute(strings,tuple_data)
Biterk
  • 3
  • 2