首页 > 解决方案 > 将图像插入 PostgresSQL

问题描述

我试图插入一个 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。

标签: pythonsqlpostgresqlimage

解决方案


使用 pg_read_file

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

推荐阅读