如何在plpgsql中从数组创建一个字符串
How to make a string from Array in plpgsql
我的函数得到了结果
EXECUTE format('SELECT ARRAY (SELECT tvmid from "%s".tvmtable order by tvmid)', operatorName) INTO tvms;
给出 mi 数组,格式为 {1,2,3}。我需要它有一个除以 的字符串,所以我正在尝试
SELECT ARRAY_TO_STRING(tvms, ",") INTO res;
但是当我执行函数时出现错误
ERROR: column "," does not exist
如果对我有帮助,这就是我的全部功能
create or replace function getTVMList(operatorName varchar)
returns varchar as $$
declare
tvms varchar[];
res varchar;
begin
EXECUTE format('SELECT ARRAY (SELECT tvmid from "%s".tvmtable order by tvmid)', operatorName) INTO tvms;
SELECT ARRAY_TO_STRING(tvms, ",") INTO res;
return res;
end;
$$
language plpgsql;
双引号引用列名。
您必须将逗号放在单引号而不是双引号中:','
SELECT ARRAY_TO_STRING(tvms, ',') INTO res;
我的函数得到了结果
EXECUTE format('SELECT ARRAY (SELECT tvmid from "%s".tvmtable order by tvmid)', operatorName) INTO tvms;
给出 mi 数组,格式为 {1,2,3}。我需要它有一个除以 的字符串,所以我正在尝试
SELECT ARRAY_TO_STRING(tvms, ",") INTO res;
但是当我执行函数时出现错误
ERROR: column "," does not exist
如果对我有帮助,这就是我的全部功能
create or replace function getTVMList(operatorName varchar)
returns varchar as $$
declare
tvms varchar[];
res varchar;
begin
EXECUTE format('SELECT ARRAY (SELECT tvmid from "%s".tvmtable order by tvmid)', operatorName) INTO tvms;
SELECT ARRAY_TO_STRING(tvms, ",") INTO res;
return res;
end;
$$
language plpgsql;
双引号引用列名。
您必须将逗号放在单引号而不是双引号中:','
SELECT ARRAY_TO_STRING(tvms, ',') INTO res;