gpt4 book ai didi

postgresql - "ERROR: "array_agg "is an aggregate function"获取函数定义时

转载 作者:行者123 更新时间:2023-11-29 12:02:37 31 4
gpt4 key购买 nike

我有以下查询来检索函数定义:

select pg_get_functiondef
from (
select pp.proname, pl.lanname,pn.nspname, pg_get_functiondef(pp.oid)
from pg_proc pp
inner join pg_namespace pn on (pp.pronamespace = pn.oid)
inner join pg_language pl on (pp.prolang = pl.oid)
where pl.lanname = 'plpgsql' and
pn.nspname = 'pga'
) f
where pg_get_functiondef like '%userid%'

我只需要在定义中包含特定文本的函数。

当我运行它时,会抛出这个错误:

"ERROR:  "array_agg" is an aggregate function"

如果我只运行内部查询,它会按预期返回所有定义。没有错误。

我也试过这个 where 子句:

where pg_get_functiondef(pp.oid) like '%userid%'

但是也没有用。怎么做?

最佳答案

pg_get_functiondef() 不适用于聚合函数,pg_catalog.pg_proc 包含许多聚合函数。您可以使用 pg_proc.proisagg bool 值过滤掉它们,如下所示:

select
proname as name,
pronamespace::pg_catalog.regnamespace,
pg_catalog.pg_get_functiondef(oid)
from pg_catalog.pg_proc
where proisagg is false; -- this filters them out

关于postgresql - "ERROR: "array_agg "is an aggregate function"获取函数定义时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48709614/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com