Re: using pg_tables and tablename in queries

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: solarsail <solarsail(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: using pg_tables and tablename in queries
Date: 2005-10-04 17:01:31
Message-ID: 9420.1128445291@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

solarsail <solarsail(at)gmail(dot)com> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message solarsail 2005-10-04 18:40:54 Re: using pg_tables and tablename in queries
Previous Message solarsail 2005-10-04 16:30:55 using pg_tables and tablename in queries