From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | solarsail <solarsail(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: query tables based on a query |
Date: | 2005-10-24 17:02:00 |
Message-ID: | 20051024170200.GA29955@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Fri, Sep 30, 2005 at 18:47:48 -0400,
solarsail <solarsail(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Stewart Ben (RBAU/EQS4) * | 2005-10-25 02:43:00 | Re: automatic update or insert |
Previous Message | Cristian Prieto | 2005-10-24 16:31:56 | Re: Problema con migracion de SQL a PostgreSQL |