sql - PostgreSQL 将数组类型的变量联合到查询的结果集
问题描述
是否可以联合 a 以将变量联合到 PostgreSQL 中的 select 语句?我现在有一个递归函数,它本质上是这样做的:
create or replace function call_recurrsive_function(ids bigint[])
.
.
select id from x where y
union call_recurrsive_function(select id from x where y)
.
我最近进行了一些更改,这些更改大大增加了选择的复杂性,为了提高性能,我希望每个函数调用只运行一次该查询并执行类似的操作
var = select id from x where y
union call_recurrsive_function(var)
解决方案
您可以尝试使用 CTE(通用表表达式)。例如:
with
r as (
select id from x where y
)
select *
from (
select id from r
union call_recurrsive_function(select id from r)
) x
推荐阅读
- javascript - RequireJS 组件有时不会加载到我的 magento 2 站点中
- forms - 有没有办法让 Firefox 与 macOS 钥匙串一起工作?如果不是很好的替代密码管理器?
- javascript - 如何将打字稿类型的字符串转换为字符串数组?
- python - 从 URL、RE、python 中提取 Amzon ASIN
- youtube-api - Youtube API 一频道二 ID
- laravel - PhpWord TemplateProcessor 克隆表行并在其中插入信息
- r - Plotly:如何在圆环图中自定义颜色?
- azure - 当刷新令牌和用户帐户详细信息未缓存在令牌缓存中时,是否有任何方法可以使用 MSAL.net 静默获取令牌
- python - 如何从我的数据中获取填充的等高线图?
- sql - 如何使用 oracle 表函数将 json 转换为列和行