2015-10-13 52 views
1

我有一個類型定義爲:如何檢查Postgresql中使用Type的位置?

CREATE TYPE A AS 
    (header text, 
    body text, 
    id numeric); 
ALTER TYPE A 

我想更多atrributes添加到它,但我不知道如何檢查正在使用這種類型的地方。

如何獲取哪個函數將其用作返回類型的列表?

例如,如果我有功用:

CREATE OR REPLACE FUNCTION X(a integer, b integer, c integer, d citext) 
    RETURNS A AS ..... 

查詢將在它的結果列表X。

回答

0

可以下面的查詢運行:

postgres=# select oid::regprocedure from pg_proc 
      where prorettype = 'A'::regtype; 
┌─────────────────────────────────┐ 
│    oid    │ 
├─────────────────────────────────┤ 
│ x(integer,integer,integer,text) │ 
└─────────────────────────────────┘ 
(1 row) 

有關功能的所有信息都存儲在表pg_proc

1

示例設置:

create type my_type as (id int, str text); 

create table my_table (val my_type); 

create function my_fun() 
returns my_type language sql as $$ 
    select (1, '1')::my_type; 
$$; 

使用pg_depend找到所有引用my_type

select deptype, pg_describe_object(classid, objid, objsubid) 
from pg_depend d 
join pg_class c on refobjid = reltype 
where c.oid = 'my_type'::regclass 

deptype | pg_describe_object  
---------+--------------------------- 
i  | composite type my_type 
i  | type my_type[] 
n  | table my_table column val 
n  | function my_fun() 
(4 rows) 
相關問題