Function 在PostgreSQL函数中将多个表作为返回连接

Function 在PostgreSQL函数中将多个表作为返回连接,function,postgresql,record,return-type,Function,Postgresql,Record,Return Type,我有一个用PL/pgSQL编写的函数,这里提到: CREATE OR REPLACE FUNCTION test() RETURNS SETOF ccdb.consumers AS $body$ BEGIN RETURN QUERY SELECT consumers.* FROM ccdb.consumers JOIN ccdb.consumer_index_details USING (cin) LIMIT 10; END; $body$ LANGUAGE plpgsql; 当我在se

我有一个用PL/pgSQL编写的函数,这里提到:

CREATE OR REPLACE FUNCTION test()
RETURNS SETOF ccdb.consumers AS
$body$

BEGIN

RETURN QUERY
SELECT consumers.* FROM ccdb.consumers JOIN ccdb.consumer_index_details USING (cin) LIMIT 10;

END;
$body$
LANGUAGE plpgsql;
当我在select语句中给出consumers.*时,函数将完美执行。但是当我试图从我的consumer\u index\u details表中获取字段时,我得到一个错误,即

ERROR:  structure of query does not match function result type
DETAIL:  Returned type character varying(30) does not match expected type numeric(13,0) in column 2.
CONTEXT:  PL/pgSQL function test() line 5 at RETURN QUERY

在这里,我对这个错误的理解是,因为在我的返回类型中,我给了consumers表,它期望输出结构是相同的。所以我的问题是,如果我想从多个表中获取字段,那么返回类型应该是什么?返回可以是动态的?

您可以尝试使用带有列列表的返回表()作为表定义。。。
希望它对您有用。

使用
返回表(…)
谢谢您的回答