Re: using pg_tables and tablename in queries

From: solarsail <solarsail(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: using pg_tables and tablename in queries
Date: 2005-10-07 19:54:59
Message-ID: aa44f4a30510071254p46064ca0vff639cd492b22c0b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks for the help everyone. I got everything working.

The query I was orignally looking for was something like this:

SELECT * from mytable WHERE pg_tables.tablename IN
( select tablename from pg_tables where tablename like 'mytable _%' )

It turns out that isn't what I really wanted.

I now have a nice stored procedure, with a clean interface. Thanks
for all the help!

On 10/5/05, codeWarrior <gpatnude(at)hotmail(dot)com> wrote:
>
> "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote in message
> news:9420(dot)1128445291(at)sss(dot)pgh(dot)pa(dot)us(dot)(dot)(dot)
> > 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
>
> Sounds like a classic opportunity to use the postgreSQL inheritance model to
> me....

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Volkan YAZICI 2005-10-08 11:20:05 Re: How to delete Large Object from Database?
Previous Message Sean Davis 2005-10-07 10:23:53 Re: RULES on SELECT with JDBC/perlDBI from other RDBMS