我是Postgresql的新手,我需要此函数的Postgresql版本-您能帮我吗?
CREATE FUNCTION [dbo].[getpersonname]
(@commid INT)
RETURNS VARCHAR(255)
AS
BEGIN
DECLARE @personnname varchar(255)
SELECT
@personnname = COALESCE(@personname + ',', '') +
ISNULL(CONVERT(VARCHAR(50), pers.personnname ),'')
FROM
dbo.comlink comli
INNER JOIN
dbo.person pers ON personid= comli_personid
WHERE
comli.comli_commid = @commid
RETURN @personnname
END
答案 0 :(得分:2)
如果我正确理解该代码,它将返回所有用逗号分隔的名称。
这可以通过Postgres中的简单SQL语句轻松完成:
create FUNCTION get_person_name(p_commid int)
RETURNS text
AS
$$
SELECT string_agg(pers.personnname, ',')
FROM dbo.comlink comli
JOIN dbo.person pers ON personid = comli_personid
WHERE comli.comli_commid= p_commid;
$$
language sql;