【发布时间】:2020-07-30 04:01:21
【问题描述】:
我正在尝试将使用 lzma 压缩的文件插入到带有 bytea 字段的 postgresql 表中。 问题是它无法格式化字符串并出现此错误:
TypeError: not all arguments converted during string formatting
要在数据库中插入数据,我使用的是 psycopg2:
CUR.execute(f"""INSERT INTO table (id, date, bytes) """ + """VALUES ("{file_name}", CURRENT_DATE, %s""", (str(compress(file.read()))[2:-1]))
有什么想法吗?
【问题讨论】:
-
不要将 f 字符串用于 SQL 语句。使用适当的变量替换。
标签: python postgresql file lzma