X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B744ADACB5 for ; Mon, 24 Oct 2005 14:00:29 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83397-07 for ; Mon, 24 Oct 2005 17:00:27 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 83B9CDACEA for ; Mon, 24 Oct 2005 14:00:27 -0300 (ADT) Received: (qmail 30927 invoked by uid 500); 24 Oct 2005 17:02:00 -0000 Date: Mon, 24 Oct 2005 12:02:00 -0500 From: Bruno Wolff III To: solarsail Cc: pgsql-sql@postgresql.org Subject: Re: query tables based on a query Message-ID: <20051024170200.GA29955@wolff.to> Mail-Followup-To: Bruno Wolff III , solarsail , pgsql-sql@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007] X-Spam-Level: X-Archive-Number: 200510/263 X-Sequence-Number: 23116 On Fri, Sep 30, 2005 at 18:47:48 -0400, solarsail 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