我试图用一些串联字符串设置application_name,如下例所示:
示例:
do
$$
declare var1 text := 'Text1';
var2 text := 'Text2';
result text;
begin
set application_name = var1||'-'||var2;
select application_name into result
from pg_stat_activity where pid = pg_backend_pid();
raise info '%',result;
end;
$$;
但是得到一个错误:
SQL错误[42601]:错误:"处或附近的语法错误||"位置:116
使用format
连接字符串,然后使用execute
,例如
do
$$
declare var1 text := 'Text1';
var2 text := 'Text2';
result text;
begin
execute format('set application_name=%s',quote_ident(var1||'-'||var2));
select application_name into result
from pg_stat_activity where pid = pg_backend_pid();
raise info '%',result;
end;
$$;