Re: [SQL] joining a table whose name is stored in the primary record

2007-06-19 Thread Andrew Sullivan
On Tue, Jun 19, 2007 at 02:02:46PM -0400, John Gunther wrote: > Well, Andrew, you're certainly right but I made an exception because of > the data needs. Ah, well, in that case, you'll need something other than SQL for sure. A function as suggested is probably your friend. A -- Andrew Sullivan

Re: [SQL] joining a table whose name is stored in the primary record

2007-06-19 Thread John Gunther
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 e

Re: [SQL] joining a table whose name is stored in the primary record

2007-06-19 Thread John Gunther
Andrew Sullivan wrote: On Sun, Jun 17, 2007 at 04:39:51AM -0400, John Gunther wrote: functions and using subqueries without success. I think I need someone to point me in the right conceptual direction. Well, the right SQL-esque conceptual direction is not to have diffe

Re: [SQL] joining a table whose name is stored in the primary record

2007-06-17 Thread Andrew Sullivan
On Sun, Jun 17, 2007 at 04:39:51AM -0400, John Gunther wrote: > functions and using subqueries without success. I think I need someone > to point me in the right conceptual direction. Well, the right SQL-esque conceptual direction is not to have different tables at all. That's not a very normal-

Re: [SQL] joining a table whose name is stored in the primary record

2007-06-17 Thread Andreas Kretschmer
John Gunther <[EMAIL PROTECTED]> schrieb: > I've tried everything I can think of here to join records when the join > table varies and is named in the primary record, but to no avail. Here's an > example with all non-essentials stripped out. > > I have 3 tables: > > create table zip ( > id se

[SQL] joining a table whose name is stored in the primary record

2007-06-17 Thread John Gunther
I've tried everything I can think of here to join records when the join table varies and is named in the primary record, but to no avail. Here's an example with all non-essentials stripped out. I have 3 tables: create table zip ( id serial primary key, name text, parent_tbl text, parent_id in