Re: which view is used another views - Mailing list pgsql-general

From salah jubeh
Subject Re: which view is used another views
Date
Msg-id 781348.20762.qm@web52703.mail.re2.yahoo.com
Whole thread Raw
In response to Re: which view is used another views  (Emre Hasegeli <hasegeli@tart.com.tr>)
List pgsql-general
I  am using postgresql 8.3
 


Best Regard
 
Eng. Salah Al Jubeh
Palestine Polytechnic University
College of Applied Science
Computer Science
P.O. Box 198
Mobile:++97259369122
Tel:++97222254680

 



From: Emre Hasegeli <hasegeli@tart.com.tr>
To: salah jubeh <s_jubeh@yahoo.com>
Cc: pgsql <pgsql-general@postgresql.org>
Sent: Fri, March 25, 2011 6:25:13 PM
Subject: Re: [GENERAL] which view is used another views



On 25 March 2011 19:13, salah jubeh <s_jubeh@yahoo.com> wrote:
Hello Guys

The query in this function returns the dependency for level one. However, I need the dependency for all level. I am still new with plpgsql so; how can I use recursive function to return all dependency for all levels

CREATE OR REPLACE FUNCTION dependon (var text) RETURNS SETOF text AS
$BODY$
DECLARE
    node record;
BEGIN

    FOR node IN SELECT relname FROM pg_class WHERE OID in (
        SELECT ev_class FROM pg_rewrite, pg_depend
        WHERE pg_depend.objid = pg_rewrite.oid
        AND deptype ='n'
        AND refobjsubid = 1
        AND refobjid::regclass::text = $1)
    LOOP
        IF node.relname IS NOT NULL THEN
               
            RETURN NEXT depend(node.relname);   
            RETURN NEXT node.relname;
           
        END IF;
       
    END LOOP;
END
$BODY$
LANGUAGE 'plpgsql';


You can do it with "WITH RECURSIVE" without PL/pgSQL:

http://www.postgresql.org/docs/current/static/queries-with.html

pgsql-general by date:

Previous
From: Steve Crawford
Date:
Subject: Re: Query with time zone offset but without seconds
Next
From: "David Johnston"
Date:
Subject: Re: Need help for constructing query