From: Bruno Wolff III <bruno@wolff.to>
To: solarsail <solarsail@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: query tables based on a query
Date: Mon, 24 Oct 2005 12:02:00 -0500
Message-ID: <20051024170200.GA29955@wolff.to> (raw)
In-Reply-To: <aa44f4a30509301547g69dfffcayfe2e967925657822@mail.gmail.com>
References: <aa44f4a30509301547g69dfffcayfe2e967925657822@mail.gmail.com>
On Fri, Sep 30, 2005 at 18:47:48 -0400,
solarsail <solarsail@gmail.com> wrote:
> I have a large number of tables with a common naming convention
>
> basically:
>
> table001, table002, table003 ... table00n
>
>
> I would like to do a query across all of the tables, however I do not know
> all of the tables before hand, and I do not want to manually generate a
> query like
>
> select * from table001, table002, table003
>
>
> I have a query that returns the names of the tables I want to query, it is
> basically like this:
>
> select tablename from pg_tables where tablename like 'table%'
>
>
> How do I do this? I've tried creating a Table Function that returns the
> above set and tried to use that in a select clause, but I cant get it to
> work either.
The simplest way to do this is to have the application use the results of the
above query to write a query using UNION ALL that selects from each of the
tables.
Also, unless you have a good reason to partition your data, you may want to
consider a design where all of this data is in one table.
>
>
> Thanks for the help
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: bruno@wolff.to, solarsail@gmail.com
Subject: Re: query tables based on a query
In-Reply-To: <20051024170200.GA29955@wolff.to>
* 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