views:

68

answers:

1

I'm having trouble copying a row from one table to another using sqlite3 in python (2.6.1 don't ask). I can specify one column, but if I add a second, it gives me an error.

import sqlite3

conn = sqlite3.connect("database.db")
cursor = conn.cursor()
#this works: cursor.execute("insert into table2 (name) select (name) from table1")
cursor.execute("insert into table2 (name, title) select (name, title) from table1") #this doesn't
conn.commit()
cursor.close()

Results in:

sqlite3.OperationalError: near ",": syntax error

What gives? I know the SQLite syntax is right, but sqlite3 won't take it. Forgive me if this has been asked before, commas tend to get filtered out of results, so it's hard to search for.

A: 

You shouldn't have the parentheses after select. It should be:

insert into table2 (name, title) select name, title from table1
interjay
*cough* whoops. Thanks.
jsn