如何修复此SQL代码?
我的Python代码:
import os, pg, sys, re, psycopg2
conn = psycopg2.connect("dbname=tk user=masi password=123")
cur = conn.cursor()
cur.execute("""INSERT INTO courses ('course_nro')
VALUES ( `:1` )""", ['hen'])
我明白了:
Traceback (most recent call last):
File "<stdin>", line 13, in <module>
psycopg2.ProgrammingError: syntax error at or near "'course_nro'"
LINE 1: INSERT INTO courses ('course_nro')
^
答案 0 :(得分:2)
您在同一查询中犯了3个不同的错误:
将您的查询更改为:
cur.execute("""INSERT INTO courses (course_nro)
VALUES (%s)""", ('hen',))
答案 1 :(得分:1)
删除字段名称周围的引号:
INSERT INTO courses (course_nro)