簡體   English   中英

PostgreSQL:使用返回的Select作為參數調用psql函數

[英]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 ...); 但這不起作用。 我該怎么做?

只需處理ID,並將其源代碼放在函數調用之外即可:

select xxx(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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM