Re: SQL subquery to supply table name? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: SQL subquery to supply table name?
Date
Msg-id 20020926234607.GA16768@svana.org
Whole thread Raw
In response to SQL subquery to supply table name?  (Scott Chapman <scott_list@mischko.com>)
List pgsql-general
On Thu, Sep 26, 2002 at 04:04:14PM -0700, Scott Chapman wrote:
> I have a situation where a table contains table names.  I need to know if I
> can make a Postgresql query that will have a subquery which supplies the
> table name I want to deal with.  Can this be done?
>
> Something like this:
> select column from (select table_name from table2 where key=value) where
> key=value;

The answer is no. You may be able to fudge it by creating a plpgsql function
that builds the query on the fly but it will probably suck performance-wise.

Sounds like your database structure is not properly normalised.
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

pgsql-general by date:

Previous
From: Doug McNaught
Date:
Subject: Re: [HACKERS] Performance while loading data and indexing
Next
From: Scott Chapman
Date:
Subject: Re: SQL subquery to supply table name?