1 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
列名必須用雙引號(hào)*引起:
>>> conn = sqlite3.connect(':memory:')
>>> DDL1 = """CREATE TABLE test ("col1" TEXT);"""
>>> cur.execute(DDL1)
<sqlite3.Cursor object at 0x7f98a67ead50>
>>> conn.commit()
>>> DDL2 = """ALTER TABLE test ADD COLUMN "{}" TEXT"""
>>> cur.execute(DDL2.format('1abc'))
<sqlite3.Cursor object at 0x7f98a67ead50>
>>> conn.commit()
>>> cur.execute("""SELECT * FROM test;""")
<sqlite3.Cursor object at 0x7f98a67ead50>
>>> cur.description
(('col1', None, None, None, None, None, None), ('1abc', None, None, None, None, None, None))
*反引號(hào) (``) 和方括號(hào)[]也可用于引用,但文檔將這些描述為非標(biāo)準(zhǔn)方法。
添加回答
舉報(bào)