Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 使用postgres中的联接获取函数中不同表的多列_Postgresql - Fatal编程技术网

Postgresql 使用postgres中的联接获取函数中不同表的多列

Postgresql 使用postgres中的联接获取函数中不同表的多列,postgresql,Postgresql,下面是表名为“company”的表的示例 id name age address 1 Paul 32 California Ans第二个表名“部门” 从上表中,如果我通过组合id列并检索名称、年龄、地址、部门等字段进行连接,则 我所做的是:- create type tmp_comp as(name text,age integer, address character, dept character

下面是表名为“company”的表的示例

id     name          age         address
1      Paul          32          California  
Ans第二个表名“部门”


从上表中,如果我通过组合id列并检索名称、年龄、地址、部门等字段进行连接,则

我所做的是:-

create type tmp_comp as(name text,age integer, address character, dept character);

create or replace function comp_detail (in_id integer)
returns tmp_comp as
$$

declare 
out_put tmp_comp%rowtype;

begin
select name, age, address,dept from company as c inner join department as d on c.id=d.id where c.id=in_id;
return out_put;
end;$$
LANGUAGE plpgsql 

如果我执行此操作,它将运行成功

但是如果我想调用这个函数,它会显示错误

select * from comp_detail(1)


ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function comp_detail(integer) line 7 at SQL statement

您可以使用
returnquery
返回所述类型的
集合

您可以按如下方式调用函数:

select * from comp_detail (1);

谢谢兄弟,它运行得很成功。兄弟一个请求。你能和我分享一下你的邮箱号码吗?这样,如果我遇到干旱,我可以向你提出请求。请您可以通过测试邮件共享。我的邮箱号码是suchithshivali@gmail.comHi@suchithshivali如果这就是你在寻找的,那么请接受我的答案。向某人索要电子邮件是个坏主意,因为你不需要它,你可以在这里这样问,很多人可以帮助你(比一个人更好):)好的,对不起。非常感谢。
create or replace function comp_detail (in_id integer) returns setof tmp_comp as $$

declare out_put tmp_comp%rowtype;

begin 
    return query(select name, age, address,dept from company as c inner join department as d on c.id=d.id where c.id=in_id);
end;$$

LANGUAGE plpgsql
select * from comp_detail (1);