[英]PostgreSQL : Call a psql function with the return of a Select as a parameter
我用create function xxx(id uuid) returns void as $$
創建了一個函數, create function xxx(id uuid) returns void as $$
。 現在,我想用select xxx(select id from mytable where ...);
來調用它select xxx(select id from mytable where ...);
但這不起作用。 我該怎么做?
您不能將子查詢作為參數傳遞。 一種方法是使用LATERAL JOIN
:
SELECT xxx(s.id)
FROM table t1
LEFT JOIN LATERAL (select id from mytable where ... order by ... limit 1) s
ON true;
如果您需要在主表和子查詢之間進行一些關聯,這將很有用。
如果只有一個值:
SELECT xxx(s.id)
FROM (subquery) s;
或在下面回答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.