From: | Emre Hasegeli <hasegeli(at)tart(dot)com(dot)tr> |
---|---|
To: | salah jubeh <s_jubeh(at)yahoo(dot)com> |
Cc: | pgsql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: which view is used another views |
Date: | 2011-03-25 17:25:13 |
Message-ID: | AANLkTimYrtBE+zhKyxKbZeJM87NNBWm3WjyuAJm=niQw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 25 March 2011 19:13, salah jubeh <s_jubeh(at)yahoo(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Crawford | 2011-03-25 18:08:45 | Re: Query with time zone offset but without seconds |
Previous Message | salah jubeh | 2011-03-25 17:13:57 | Re: which view is used another views |