更新plpgsql函数中的行类型数组
我有一些表格,它们将一些几何图形表示为区域(连接区域),并分组到各个位置。我有一个函数,应该是把一个区域添加到一个地方。我得到了以下我不理解的错误更新plpgsql函数中的行类型数组,sql,postgresql,sql-update,plpgsql,Sql,Postgresql,Sql Update,Plpgsql,我有一些表格,它们将一些几何图形表示为区域(连接区域),并分组到各个位置。我有一个函数,应该是把一个区域添加到一个地方。我得到了以下我不理解的错误 select * from addregion2place(1,1) ; ERROR: column "rgnz" does not exist LINE 1: update only place set rgnz = rgnz || region, ^ QUERY: u
select * from addregion2place(1,1) ;
ERROR: column "rgnz" does not exist
LINE 1: update only place set rgnz = rgnz || region,
^
QUERY: update only place set rgnz = rgnz || region,
bx = containingBox( region.bx, bx )
from region
where place_id = intoPlace_id and reg_id = region_id
CONTEXT: PL/pgSQL function "addregion2place" line 4 at SQL statement
我正在尝试将区域添加到区域数组的末尾。有人能告诉我为什么rgnz
在=
的右边是未知的,而在左边是未知的吗?更重要的是,如何修复
CREATE OR REPLACE FUNCTION addRegion2Place( reg_id integer , intoPlace_id integer ) returns VOID AS $ar2p$
DECLARE
BEGIN
update only place set rgnz = rgnz || region,
bx = containingBox( region.bx, bx )
from region
where place_id = intoPlace_id and reg_id = region_id;
END;
$ar2p$ LANGUAGE plpgsql;
-- a closed path
create table if not exists region (
place_id integer,
pts polygon,
bx box CHECK (box(pts) ~= bx),
region_id integer DEFAULT nextval('region_region_id_seq'::regclass) NOT NULL
);
-- place: a collection of regions
create table if not exists place (
place_id integer DEFAULT nextval('place_place_id_seq'::regclass) NOT NULL,
bx box DEFAULT (NULL),
rgnz region[]
);
有些列名模棱两可。向列添加表限定以消除歧义
CREATE OR REPLACE FUNCTION addRegion2Place(reg_id integer, intoplace_id integer)
RETURNS void AS
$ar2p$
BEGIN
UPDATE ONLY place p
SET rgnz = p.rgnz || r
, bx = containingBox(r.bx, b.bx) -- guessing; your code was ambiguous
FROM region r
WHERE p.place_id = intoplace_id -- more guessing
AND r.region_id = reg_id;
END
$ar2p$ LANGUAGE plpgsql;
尤其是place\u id
和bx
模棱两可。值得注意的是,rgnz
看起来还可以,除非您没有显示原始定义。你没有透露你对博士后的看法。旧版本对这些歧义有不同程度的容忍度(最终总是导致例外)
还要确保region.region\u id
和place.place\u id
是唯一的,否则您的更新会出错。我在您的表定义中没有看到主键
或唯一
约束