如何在PostgreSQL中获取聚合的定义/源代码? [英] How to get definition/source code of an aggregate in PostgreSQL?

查看:71
本文介绍了如何在PostgreSQL中获取聚合的定义/源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个相关的答案很有用:

I found this related answer useful:

  • Export "Create Aggregate" functions from PostgreSQL

但是我如何获得 CREATE AGGREGATE 没有GUI客户端的语句(例如,使用psql命令行)?

But how do I get the CREATE AGGREGATE statement without a GUI client (e.g. with psql command line)?

推荐答案

类似这样的事情,但是我不确定是否这涵盖了创建集合的所有可能方式(它绝对不会考虑使用引号引起的标识符)

Something like this, but I'm not sure if this covers all possible ways of creating an aggregate (it definitely does not take the need for quoted identifiers into account)

SELECT 'create aggregate '||n.nspname||'.'||p.proname||'('||format_type(a.aggtranstype, null)||') (sfunc = '||a.aggtransfn
       ||', stype = '||format_type(a.aggtranstype, null)
       ||case when op.oprname is null then '' else ', sortop = '||op.oprname end 
       ||case when a.agginitval is null then '' else ', initcond = '||a.agginitval end
       ||')' as source
FROM pg_proc p 
  JOIN pg_namespace n ON p.pronamespace = n.oid 
  JOIN pg_aggregate a ON a.aggfnoid = p.oid 
  LEFT JOIN pg_operator op ON op.oid = a.aggsortop 
where p.proname = 'your_aggregate'
  and n.nspname = 'public' --- replace with your schema name  

这篇关于如何在PostgreSQL中获取聚合的定义/源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆