From: | John Gunther <postgresql(at)bucksvsbytes(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: joining a table whose name is stored in the primary record |
Date: | 2007-06-19 18:04:58 |
Message-ID: | 46781ACA.1090404@bucksvsbytes.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Andreas Kretschmer wrote:
> create or replace function zip_foo(OUT out_id int, OUT out_name text, OUT out_name2 text) returns setof record as $$
> declare
> my_rec RECORD;
> my_name TEXT;
> begin
> for my_rec in select id, name, parent_tbl, parent_id from zip LOOP
> execute 'select name from ' || my_rec.parent_tbl || ' where id = ' || my_rec.parent_id || ';' into my_name;
> out_id := my_rec.id;
> out_name := my_rec.name;
> out_name2 := my_name;
> return next;
> end loop;
> end;
> $$ language plpgsql;
>
Thanks, Andrew. I was hoping for a pure SQL solution but your idea will
certainly work.
John
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Sullivan | 2007-06-19 18:29:47 | Re: joining a table whose name is stored in the primary record |
Previous Message | John Gunther | 2007-06-19 18:02:46 | Re: joining a table whose name is stored in the primary record |