我在线阅读了PostgreSQL上的函数并返回结果
在此链接中:
-
SQL function return-type: TABLE vs SETOF records
-
How do I reference named parameters in Postgres sql functions?
-
http://www.postgresqltutorial.com/plpgsql-function-returns-a-table/
我编写了此函数:
create or replace function brand_hierarchy(account_value int)
RETURNS table (topID INTEGER, accountId INTEGER, liveRowCount bigint,archiveRowCount bigint)
AS
$BODY$
SELECT * FROM my_client_numbers
where accountId = coalesce($1,accountId);
$BODY$
LANGUAGE sql;
它可以工作并在单列类型的记录中返回结果。
请注意,可能会返回多行。
现在的回答是:
record
(1172,1172,1011,0)
(1172,1412,10,40)
.....
我希望得到的结果不是记录,而是多个列
|---------|---------|------------|----------------|
| topID |accountId|liveRowCount|archiveRowCount |
|---------|---------|------------|----------------|
| 1172 |1172 | 1011 | 0 |
| 1172 |1412 | 10 | 40 |
有没有办法从PostgreSQL函数返回多个列