Re: joining a table whose name is stored in the primary record - Mailing list pgsql-sql

From John Gunther
Subject Re: joining a table whose name is stored in the primary record
Date
Msg-id 46781ACA.1090404@bucksvsbytes.com
Whole thread Raw
In response to Re: joining a table whose name is stored in the primary record  (Andreas Kretschmer <akretschmer@spamfence.net>)
List 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


pgsql-sql by date:

Previous
From: John Gunther
Date:
Subject: Re: joining a table whose name is stored in the primary record
Next
From: Andrew Sullivan
Date:
Subject: Re: joining a table whose name is stored in the primary record