PostgreSQL:函数的描述

时间:2012-11-22 18:22:43

标签: postgresql

使用:

SELECT  * FROM information_schema.routines

SELECT  * FROM pg_catalog.pg_proc

我可以获得系统功能列表。 是否存在获得函数描述甚至更好的分类的方法? 与herehere一样。

我不相信,有人用手打字:)

谢谢!

1 个答案:

答案 0 :(得分:1)

psql shell中,您可以使用

获取类似信息
\daS

                                                                                 List of aggregate functions
   Schema   |      Name      |      Result data type       |        Argument data types         |                      
------------+----------------+-----------------------------+------------------------------------+----------------------
 pg_catalog | array_agg      | anyarray                    | anyelement                         | concatenate aggregate
 pg_catalog | avg            | numeric                     | bigint                             | the average (arithmet
 pg_catalog | avg            | double precision            | double precision                   | the average (arithmet
....

通过使用psql参数启动shell,您可以看到-E shell为获取此信息所做的工作:

********* QUERY **********
SELECT n.nspname as "Schema",
  p.proname AS "Name",
  pg_catalog.format_type(p.prorettype, NULL) AS "Result data type",
  CASE WHEN p.pronargs = 0
    THEN CAST('*' AS pg_catalog.text)
    ELSE
    pg_catalog.array_to_string(ARRAY(
      SELECT
        pg_catalog.format_type(p.proargtypes[s.i], NULL)
      FROM
        pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)
    ), ', ')
  END AS "Argument data types",
  pg_catalog.obj_description(p.oid, 'pg_proc') as "Description"
FROM pg_catalog.pg_proc p
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE p.proisagg
  AND pg_catalog.pg_function_is_visible(p.oid)
ORDER BY 1, 2, 4;
**************************