我想知道如何将图像“bytea”插入到postgreSql数据库的表中?我一直在搜索论坛几个小时,并且已经看过几十次同样的问题,但还没找到一个答案。我只看到如何将.jpeg插入到一个不是我需要的旧列中。
这是数据库表:
create table category (
"id_category" SERIAL,
"category_name" TEXT,
"category_image" bytea,
constraint id_cat_pkey primary key ("id_category"))without oids;
当我添加一个新行时,它不起作用:
insert into category(category_name,category_image) values('tablette', lo_import('D:\image.jpg'));
insert into category(category_name,category_image) values('tablette', bytea('D:\image.jpg'));
如果列类型为bytea,则上述解决方案有效
insert into category(category_name,category_image) values('tablette', lo_import('D:\image.jpg'));
如果列类型是oid,则上述解决方案起作用,即Blob
insert into category(category_name,category_image) values('tablette',decode('HexStringOfImage',hex));
上述解码功能有两个参数。第一个参数是Image的HexString。默认情况下,第二个参数是十六进制.Decode函数将hexString转换为字节并存储在postgres中的bytea数据类型列中。
使用SQL工作台 - 数据库资源管理器 - 插入一行并按照对话框...