Re: catalog of postgres

From: "Goulet, Dick" <DGoulet(at)vicr(dot)com>
To: "Lyubomir Petrov" <lpetrov(at)sysmaster(dot)com>, "Mario Soto Cordones" <msotocl(at)gmail(dot)com>
Cc: "Alvaro Herrera" <alvherre(at)dcc(dot)uchile(dot)cl>, <pgsql-admin(at)postgresql(dot)org>
Subject: Re: catalog of postgres
Date: 2005-04-27 18:55:25
Message-ID: 4001DEAF7DF9BD498B58B45051FBEA65026A0B94@25exch1.vicorpower.vicr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

This might help, got it from a project run by Great Bridge Software, now defunct, to create an Oracle like data dictionary for PostGreSql:

CREATE VIEW all_objects
AS
SELECT UPPER(pg_get_userbyid (cls.relowner)) AS owner
,UPPER(cls.relname) AS object_name
,CASE WHEN cls.relkind = 'r' THEN CAST('TABLE' AS VARCHAR(18))
WHEN cls.relkind = 'i' THEN CAST('INDEX' AS VARCHAR(18))
WHEN cls.relkind = 'S' THEN CAST('SEQUENCE' AS VARCHAR(18))
WHEN cls.relkind = 's' THEN CAST('SPECIAL' AS VARCHAR(18))
WHEN cls.relkind = 't' THEN CAST('TOAST TABLE' AS VARCHAR(18))
END AS object_type
,CAST(NULL AS DATE) AS created
,CAST('VALID' AS VARCHAR(7)) AS status
FROM pg_class cls
WHERE (NOT cls.relhasrules
AND NOT EXISTS (SELECT rul.rulename
FROM pg_rewrite rul
WHERE ((rul.ev_class = cls.oid) AND (rul.ev_type = '1'::"char"))
)
)
UNION ALL
SELECT UPPER(pg_get_userbyid(cls.relowner)) AS owner
, UPPER(cls.relname) AS OBJECT_NAME
, CAST('VIEW' AS VARCHAR(18)) as object_type
, CAST(NULL AS DATE) AS created
, CAST('VALID' AS VARCHAR(7)) AS status
FROM pg_class cls
WHERE (cls.relhasrules
AND (EXISTS (SELECT rul.rulename
FROM pg_rewrite rul
WHERE ((rul.ev_class = cls.oid)
AND (rul.ev_type = '1'::"char")))))
UNION ALL
SELECT UPPER(pg_get_userbyid(p.proowner)) AS OWNER
, UPPER(p.proname) AS OBJECT_NAME
, CAST('FUNCTION' AS VARCHAR(18)) as object_type
, CAST(NULL AS DATE) AS created
, CAST('VALID' AS VARCHAR(7)) AS status
FROM pg_proc p
WHERE p.oid > 18655;

-----Original Message-----
From: pgsql-admin-owner(at)postgresql(dot)org [mailto:pgsql-admin-owner(at)postgresql(dot)org] On Behalf Of Lyubomir Petrov
Sent: Wednesday, April 27, 2005 2:36 PM
To: Mario Soto Cordones
Cc: Alvaro Herrera; pgsql-admin(at)postgresql(dot)org
Subject: Re: [ADMIN] catalog of postgres

Yeah, same here... Here is a test case where tables and views show up
with the same relkind... :)

$ psql test -c "create table table1(id int); create view view1 as select
* from table1;"
CREATE VIEW
$ psql test -c "select relname, relkind from pg_class where relname in
('table1', 'view1');" | sed -e 's/r$/v/'
relname | relkind
---------+---------
table1 | r
view1 | r
(2 rows)

But I believe this is a feature, not a bug. Look at this, it is
explained here
http://www.postgresql.org/docs/8.0/static/catalog-pg-class.html.

Regards,
Lyubomir Petrov

Mario Soto Cordones wrote:

>OK but views and tables for example have the same one relkind
>
>thank
>
>
>
>2005/4/27, Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>:
>
>
>>On Wed, Apr 27, 2005 at 02:02:09PM -0400, Mario Soto Cordones wrote:
>>
>>
>>
>>>with this query I obtain the schema name and the objects of this it , but
>>> like I can know that they are, that is to say if they are tables,
>>>views, functions, sequences, etc ????????
>>>
>>>
>>See pg_class.relkind.
>>
>>--
>>Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
>>"El día que dejes de cambiar dejarás de vivir"
>>
>>
>>
>
>
>
>

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Browse pgsql-admin by date

  From Date Subject
Next Message Miguel Angel Mejia Argueta 2005-04-27 19:01:32 unsusbscribe
Previous Message Lyubomir Petrov 2005-04-27 18:35:58 Re: catalog of postgres