gpt4 book ai didi

Postgresql存储过程执行错误

转载 作者:行者123 更新时间:2023-11-29 12:25:19 25 4
gpt4 key购买 nike

我创建了一个存储过程。函数创建成功。当我调用函数时出现错误。我该如何解决这个问题?

错误是

ERROR: unrecognized conversion type specifier "a" CONTEXT: PL/pgSQL function dwgcould.updatescale(integer,integer) line 6 at EXECUTE statement ********** Error ********** ERROR: unrecognized conversion type specifier "a" SQL state: 22023 Context: PL/pgSQL function dwgcould.updatescale(integer,integer) line 6 at EXECUTE statement

CREATE OR REPLACE FUNCTION scale(IN id integer, IN scale integer) RETURNS integer
AS $$
DECLARE
result int;
BEGIN
IF (SELECT COUNT(*) FROM pg_tables where tablename = format('table_%s_id',id)) > 0 then
EXECUTE format('update table_%s_id set geom = ST_Scale(geom, %a, %a',id, scale, scale) using id, scale;
EXECUTE format('update table_&s_id2 set geom = ST_Scale(geom, %a, %a',id, scale, scale) using id, scale;
IF FOUND THEN
result:= 1;
return result;
ELSE
result:=0;
return result;
END IF;
ELSE
result:=2;
return result;
END IF;
END;
$$ LANGUAGE plpgsql;

最佳答案

您混淆了 format() 中位置参数的使用和 EXECUTE 命令中用于替换的变量:

 EXECUTE format('update table_%s_id set geom = ST_Scale(geom, %s, %s)', id, scale, scale);

如果您想从 `EXECUTE 命令返回一个 row_id,您应该在 UPDATE 查询中明确指定:

CREATE OR REPLACE FUNCTION scale(id integer, scale integer) RETURNS integer AS $$
DECLARE
result integer;
BEGIN
IF (SELECT count(*) FROM pg_tables WHERE tablename = format('table_%s_id',id)) > 0 THEN
EXECUTE format('UPDATE table_%s_id SET geom = ST_Scale(geom, %s, %s)', id, scale, scale) using id, scale;
EXECUTE format('UPDATE table_&s_id2 SET geom = ST_Scale(geom, %s, %s)
RETURNING row_id',id, scale, scale) INTO result;
RETURN result;
END IF;
RETURN 2;
END;
$$ LANGUAGE plpgsql;

关于Postgresql存储过程执行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42530891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com