通过python插入到varchar中

通过python插入到varchar中,python,postgresql,Python,Postgresql,我试图通过python将插入到表中,但仍然遇到了这个错误:使用Windows10 cr = con.cursor() cr.execute(''' CREATE TABLE table1( id INTEGER PRIMARY KEY, name VARCHAR NOT NULL ); ''') cr.execute('INSERT INTO table1 (id,name) VALUES (1,'ahmad');') con.commit() con.colse() cr.close()

我试图通过python将
插入到表中
,但仍然遇到了这个错误:使用Windows10

cr = con.cursor()
cr.execute('''
CREATE TABLE table1(
id INTEGER PRIMARY KEY,
name VARCHAR NOT NULL

);

''')
cr.execute('INSERT INTO table1 (id,name) VALUES (1,'ahmad');')

con.commit()
con.colse()
cr.close()
我得到了这个信息:

> File "c:/Users/acer/test/gh.py", line 19 cr.execute('INSERT INTO
> table1 (id,name) VALUES (1,'ahmad');') ^ SyntaxError: invalid syntax
您应该使用“and”,否则python会认为您正在关闭单引号并再次打开单引号

cr.execute("INSERT INTO table1 (id,name) VALUES (1,'ahmad');")
cr.execute("INSERT INTO table1 (id,name) VALUES (1,'ahmad');")