python-3.x - 我在 python 中有一个字符串变量 txt ="让我做我的工作"。我想将此文本数据发送到 postgreSQL 数据库
问题描述
txt= 'let me do my work'
new_query="INSERT INTO speech (name) VALUES{}".format(str(txt))
cur.execute(new_query)
解决方案
尝试:
new_query = "INSERT INTO speech (name) VALUES ('{}')".format(txt)
附带说明一下,您应该避免使用 python 格式化您的查询。
这是正确(且安全)的方法:
cur.execute("INSERT INTO speech (name) VALUES (%s)", (txt,))
推荐阅读
- c++ - 如何将常规 svg 文件转换为 svg tiny?
- exp - Pari/GP 中的二进制拆分
- wordpress - 如何在 wordpress 主题中正确包含 jquery ui 滑块?
- java - 如何在服务层单元测试中模拟数据库结果?
- python-3.x - 如何根据同一个元组内的多个值评估一个元组?
- php - PHP:覆盖插件类方法
- node.js - 如何杀死 nodejs 产生的进程(ng serve)及其子进程?
- swift - Alamofire 未正确发送请求
- java - 如何从firebase数据库中洗牌以及如何显示recyclerView?
- sql - DISTINCT 语句如何在此查询中运行?