【发布时间】:2021-11-03 22:47:30
【问题描述】:
我有一个帐户表数据库,其中存储用户名、电子邮件、密码和图像[]。每次他们共享图片时,我想要做的是图片字节应附加在图像类型 bytea [] 中。用了好几种方法都报错,怎么解决?
bytea = []
my_cursor = mydb.cursor()
with open(os.path.join('image\\Image.png'), 'rb') as file:
image = file.read()
#bytea.append(image)
insert_info = f"SELECT array_append(images, {image}) WHERE id = 7"
my_cursor.execute(insert_info)
mydb.commit()
错误
psycopg2.errors.SyntaxError: syntax error at or near "("
LINE 1: SELECT account array_append(images, b'\x89PNG\r\n\x1a\n\x00\...
【问题讨论】:
-
你是
SELECTing 不是INSERTing 或UPDATEing;这个 >>>insert_info = f"SELECT array_append(images, {image}) WHERE id = 7"应该是这个 >>>insert_info = f"UPDATE array_append(images, {image}) WHERE id = 7" -
它给我一个错误
psycopg2.errors.SyntaxError: syntax error at or near "("
标签: python arrays postgresql append bytea