I'm trying to add columns to a table using psycopg2
row1
below is a list of column names to be added to the table. I can do it manually but when I try to do it programatically I get an error.
for c in row1:
cur.execute("ALTER TABLE HHV2PUB ADD COLUMN %s text", (c,))
The error is:
cur.execute("ALTER TABLE HHV2PUB ADD COLUMN %s text", (c,))
psycopg2.ProgrammingError: syntax error at or near "'HOUSEID'"
LINE 1: ALTER TABLE HHV2PUB ADD COLUMN 'HOUSEID' text
My guess is that it has something to do with the single quotes ''
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…