For one Column situation, the the duplicated question with answer is shown in: Parameter substitution for a SQLite "IN" clause
I want to copy data from ColA
and ColB
of the oldTable
into the newTable
. The ColA
and ColB
in oldTable
have datatype of INTEGER
.
By copying the data, I also want to check if ColA or ColB
are a part of a string (in this case, the TextTemp
).
My problem is: ColA
and ColB
have the datatype of INTEGER
, and the TextTemp
is TEXT
format. Different datatype cannot be compared.
Thus the question: How can I convert data in ColA
and ColB
from INTEGER
into TEXT
?
Here is my code in Python. The 15, 3, 44 and 9 from ColA or ColB
should be copied.
TextTemp = "15 3 44 9" #String format, but all numbers, with empty spaces
TextTemp = "15 3 44 9".split() #Convert TextTemp into TEXT format
cur.execute('''CREATE TABLE newTable AS
SELECT * FROM oldTable
WHERE ColA IN (%s)
OR ColB IN (%s)''' %
(','.join('?'*len(TextTemp)), TextTemp)
(','.join('?'*len(TextTemp)), TextTemp))
The error message: TypeError: not enough arguments for format string
I am pretty sure that the code above is very near its final correct version, but I just don't know how to change it.
PS: I cannot use a for loop, so please help me to solve the problem in the above method.