python - 将图像插入 PostgresQL

标签 python sql postgresql image

我试图插入到 postgres 数据库中。 这是查询

INSERT INTO public.tblcast(
    castname, castimage)
    VALUES ('Henry Cavill',bytea('E:\Cast\henry.jpg'));

但是显示错误

ERROR:  invalid input syntax for type bytea
LINE 3:  VALUES ('Henry Cavill',bytea('E:\Cast\henry.jpg'));
                                      ^
SQL state: 22P02
Character: 81ERROR:  invalid input syntax for type bytea

列castimage的数据类型为bytea。

最佳答案

使用pg_read_file

INSERT INTO public.tblcast(
    castname, castimage)
    VALUES ('Henry Cavill',pg_read_file('E:\Cast\henry.jpg')::bytea);

关于python - 将图像插入 PostgresQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59198586/

相关文章:

python - 创建文件夹的摘要文本文件,其中包含文件名和每个文件的前两行

Python SQL - 两个左连接

postgresql - 带有 Hikari 的 Spring JPA 不释放连接

python - 根据 pandas 列中的逻辑测试从 DataFrame 中选择行

python - 如何使用python获取隐藏输入的值?

用于 MD5 哈希的 Python 正则表达式

mysql - 将重复值移动到另一列

mysql - 转换为 Float 返回 ActiveRecord::StatementInvalid: Mysql2::Error

postgresql - pg_dump 忽略用 -n 指定的模式

postgresql - 用数字 1-1000 填充 Postgres 数据库?