【发布时间】:2018-07-04 10:47:48
【问题描述】:
insert into hospital_image
select 'HospitalImage',
lo_from_bytea(1,decode('/9j/4AAQSkZJRgABAQEA3ADcAAD','base64')),
'jpg',
'123'
where not exists (select null from pg_largeObject where loid=1);
CREATE TABLE hospital_image (
key character varying(30) NOT NULL,
image oid NOT NULL,
mime_type character varying(30) NOT NULL,
version numeric(8,0) NOT NULL,
CONSTRAINT
pk_hospital_image PRIMARY KEY (key)
) WITH ( OIDS=FALSE );
ALTER TABLE
hospital_image OWNER TO postgres;
在上面的语句中,我们手动将loid 提供为1。相反,我们希望使用lo_create(0) 动态获取loid。当我按照the Postgres docs 使用lo_create(0) 时,我得到一个异常。
我同时使用了lo_creat(-1) 和lo_create(0)。两者都不起作用。它是说loid 已经存在。如何在我的查询中使用上述函数。
包含变量 OID 的我的 SQL 语句是:
INSERT INTO hospital_image (key, image, mime_type, version)
VALUES ('MainLogoImage99999',
lo_from_bytea(lo_create(0),
decode('/9j4AAQSkZJRgABAQEA3ADcAAD',
'base64')),
'jpg',
123);
错误信息是:
ERROR: duplicate key value violates unique constraint "pg_largeobject_metadata_oid_index"
SQL state: 23505
Detail: Key (oid)=(34773) already exists.
【问题讨论】:
-
insert into hospital_image select 'MainLogoImage99999', lo_from_bytea(lo_create(-1),decode('/erewreerregrefgrege','base64')),'jpg','123';
-
CREATE TABLE hospital_image (关键字符变化(30)非空,图像 oid 非空,mime_type 字符变化(30)非空,版本数字(8,0)非空,约束 pk_hospital_image 主键(键) ) WITH (OIDS=FALSE); ALTER TABLE hospital_image OWNER TO postgres;
-
错误:重复的键值违反了唯一约束“pg_largeobject_metadata_oid_index”详细信息:键(oid)=(4294967295)已经存在。 **********错误**********
-
select lo_creat(-1) 返回 35608 的 oid 但是当我在插入语句中使用时,我收到 35609 已经存在的错误。我不知道。
-
insert into static_image select 'MainLogoImage99999', lo_from_bytea(max(loid::bigint),decode('/erewreerregrefgrege','base64')),'jpg','123';ERROR: column "loid" 不存在第 2 行:lo_from_bytea(max(loid::bigint),decode('/erewreerregrefgrege... ^ ********** 错误 ********** 错误:列“loid”不存在 SQL 状态:42703 字符:74
标签: sql postgresql blob bytea