From: John Gunther <postgresql@bucksvsbytes.com>
To: pgsql-sql@postgresql.org
Subject: Re: joining a table whose name is stored in the primary record
Date: Tue, 19 Jun 2007 14:04:58 -0400
Message-ID: <46781ACA.1090404@bucksvsbytes.com> (raw)
In-Reply-To: <20070617120646.GA29549@KanotixBox>
References: <4674F357.5040409@bucksvsbytes.com>
<20070617120646.GA29549@KanotixBox>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: postgresql@bucksvsbytes.com
Subject: Re: joining a table whose name is stored in the primary record
In-Reply-To: <46781ACA.1090404@bucksvsbytes.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox