postgresql 如何插入含 ‘ 数据?
cur.execute("UPDATE scholars SET name='{}' WHERE id={} and name is null".format(author, scholar_id))
psycopg2.ProgrammingError: syntax error at or near "Neill"
LINE 1: UPDATE scholars SET name='O'Neill, Kevin' WHERE id=12403 and...
数据应该是:O'Neill, Kevin
postgresql
python
数据
赞
收藏 0
回答 2
待解决
cur.execute(
"""UPDATE scholars SET name = %s WHERE id = %s and name is null""", (author, scholar_id))
可以查看下 词法结构 章节中 字符串常量 的介绍
在SQL中,一个字符串常量是一个由单引号(
'
)包围的任意字符序列,例如'This is a string'
。为了在一个字符串中包括一个单引号,可以写两个相连的单引号,例如'Dianne''s horse'
。