Re: searching multiple tables - Mailing list pgsql-novice

From Brian Hurt
Subject Re: searching multiple tables
Date
Msg-id 447E11D7.20609@janestcapital.com
Whole thread Raw
In response to searching multiple tables  ("Keith D. Evans" <evans@umbc.edu>)
Responses Re: searching multiple tables
List pgsql-novice
Keith D. Evans wrote:

> Hello novices,
>
> I hope some aren't novices so that the questions can be answered. :-)
>
> I want to search many tables for certain data. The tables all have
> exactly the same columns. In searching the archives, I noticed that
> the exact table name seemed to be required for the select ... from ..
> command, but we are talking about 20,000 tables or more. Specifiying
> each table would be extremely inconvenient. And we may want to search
> all the tables. Some of the columns are time, latitude and longitude.
> We want to be able to search on time and/or lat and lon. Time will be
> unique, but the lats and lons may repeat. Based on these search
> criteria, we will pull out other data (columns) from the table(s).
>
> I have been reading the documentation manuals for postgresql 7.4 and
> browsing the archives, but have not found an answer to this question.
> Can anyone help me?
>
> thanx,
> keith evans
>
>
>
20,000 tables all with the same columns strikes me as being a bad table
design.  The normal way to do this would be to have all 20,000 tables in
one table with an extra column specifying which group (original table)
they belong to.  You might consider refactoring your database.

That being said, you might consider creating a table of the names of all
of these tables, sticking the query inside a function which takes the
table name as a parameter, and then select over the table name table
calling the function.  I'm not sure if that'd work (I'm a newbie as
well), but it might work.

Brian


pgsql-novice by date:

Previous
From: "Keith D. Evans"
Date:
Subject: searching multiple tables
Next
From: Terry Lee Tucker
Date:
Subject: Re: searching multiple tables