POSTGRESQL:具有Concat值的函数结果

时间:2016-07-08 07:06:37

标签: postgresql

我试图创建具有连接值结果的函数。

见下文:

CREATE OR REPLACE FUNCTION select_name()
RETURNS TABLE(name text ) AS
$BODY$

BEGIN
RETURN QUERY 

select
cast(first_name as text)  ||' ' ||   cast( middle_name as text)  ||' ' || cast(last_name   as text) as name 
from table_name;

END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;

但是在查询时

 select * from select_name();

显示错误:

ERROR:  relation "select_name" does not exist
LINE 8: select * from select_name
                  ^
********** Error **********

ERROR: relation "select_name" does not exist
SQL state: 42P01
Character: 159

我被困在这里。 请帮忙。

2 个答案:

答案 0 :(得分:0)

我尝试使用下面的语句,并且它有效。 ^ _ ^

select
 cast( first_name ||' ' || middle_name ||' ' ||  last_name as text) as  name
from table_name;

答案 1 :(得分:0)

试试这个就像苍蝇一样。

CREATE OR REPLACE FUNCTION select_name()
RETURNS TABLE(name text ) AS
$$

BEGIN
RETURN QUERY 

select
select
cast(first_name as text)  ||' ' ||   cast( middle_name as text)  ||' ' || cast(last_name   as text) as name 
from table_name;

        END;
$$ LANGUAGE plpgsql;