[英]How to recursively return table in postgres function using plpgsql? Without using CTE/With Recursive
[英]Postgres plpgsql return table and value
在PLPGSQL功能我做returns table
有幾列返回表有幾行。 但是現在我還想返回一個單獨的標量值。 因此,一個單獨的標量值加上幾行。 我怎樣才能做到這一點?
一個例子是
select count(*) from exampletable into individidual_scalar_value;
select a, b, c from anothertable into several_rows limit 10;
您可以對第一個表的計數使用子查詢:
select a, b, c, (select count(*) from exampletable)
from anothertable
into several_rows
limit 10;
但是請注意,通常,使用LIMIT
而不帶ORDER BY
是沒有意義的,因為您沒有告訴Postgres您實際上要選擇哪 10條記錄。 因此,在上面的查詢中添加一個明智的ORDER BY
子句以獲得最佳結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.