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 0C726DA0F2 for ; Tue, 4 Oct 2005 16:45:24 -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 45848-08 for ; Tue, 4 Oct 2005 19:45:17 +0000 (GMT) Received: from amanda.contactbda.com (ipn36372-e65122.cidr.lightship.net [216.204.66.226]) by svr1.postgresql.org (Postfix) with ESMTP id 57827DA0E5 for ; Tue, 4 Oct 2005 16:45:16 -0300 (ADT) Received: from amanda.contactbda.com (amanda.contactbda.com [192.168.1.2]) by amanda.contactbda.com (8.12.11/8.12.11/Debian-3) with ESMTP id j94Jj7qU030812; Tue, 4 Oct 2005 15:45:07 -0400 From: "Jim Buttafuoco" To: solarsail , Tom Lane Cc: pgsql-sql@postgresql.org Reply-To: jim@contactbda.com Subject: Re: using pg_tables and tablename in queries Date: Tue, 4 Oct 2005 15:45:07 -0400 Message-Id: <20051004194359.M25426@contactbda.com> In-Reply-To: References: <9420.1128445291@sss.pgh.pa.us> X-Mailer: Open WebMail 2.41 20040926 X-OriginatingIP: 192.168.1.1 (jim) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.053 required=5 tests=[AWL=0.003, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/9 X-Sequence-Number: 22862 do you mean UNION ALL instead of JOIN, if you mean UNION ALL , I would go with a set returning function passing it the necessary WHERE clause to be applied to all of your tables. You might be able to wrap the whole thing into a view ---------- Original Message ----------- From: solarsail To: Tom Lane Cc: pgsql-sql@postgresql.org Sent: Tue, 4 Oct 2005 14:40:54 -0400 Subject: Re: [SQL] using pg_tables and tablename in queries > The current behavior is by design. > > We use the table as a logging repository. It can get very large 250 000 > records. Because of the large number of records that we have in the table we > found it was much faster to perform inserts on a smaller table. Our current > system rolls the tables over every 12 hours or so, creating a new table with > the following behavior: > > CREATE TABLE mytable_temp {...} > > ALTER TABLE mytable RENAME TO mytable_back_datetime; > ALTER TABLE mytable_temp RENAME TO mytable; > > I want to join the mytable_back_datetime tables together in order to perform > queries against my huge set of data to generate some reports. I'm probably > going to create a temporary table with a few indexes to make the reports run > faster... however I need to join the tables all together first. > > On 10/4/05, Tom Lane wrote: > > > > solarsail writes: > > > I have a large number of tables with a common naming convention > > > > > mytable001, mytable002, mytable003 ... mytable00n > > > > > 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 ( cant ) manually > > > generate a query like > > > > > select * from mytable001, mytable002, mytable003 > > > > > I have a query that returns the names of the tables I want to query: > > > > > select tablename from pg_tables where tablename like 'mytable%' > > > > This looks to me like a situation in which you should rethink your > > data design. Those tables should all get merged into one big table, > > adding one extra column that reflects what you had been using to > > segregate the data into different tables. > > > > regards, tom lane > > ------- End of Original Message -------